Gregory
Gregory
CC#
Created by Gregory on 6/13/2023 in #help
❔ Noob trying to edit C# ASCOM code for USB Relay
I'm a noob and complete "new born" with C# go easy on me! see my notes/thoughts behind // My relay On:0ff commands A0 01 01 A2 : A0 01 00 A1 internal byte [] relaystatus = new byte [4]; //up to 4 characters in status string internal byte [] command = new byte[4]; //up to 4 characters internal byte [] txtstringlen = 3; // number of characters in KMtronic command string, I will change this to 4 for my relay internal byte [] rxstringllen = 3; // number of characters in KMTronic Reply but not sure I need this as I cannot find the 'status request command' for my relay. internal byte [] startByte = 0xFF; // KMtronic start byte. My relays start byte is 0xA0 so I will change this internal byte [] relaynumber = 0x01; // KMtronic & same as my relay: only one relay. internal byte [] setpin = 0x01; //KMtronic & same as my relay with the exception that the fourth character must be A2. Is this a variable? can i create a 'setpin2 = 0xA2'? internal byte [] clearpin = 0x00; // KMtronic & same as my relay with the exception that the fourth character must be set to A1. again can i create a 'clearpin2'? internal byte [] readpin = 0x03; //KMtronic status request command. I cannot find the status request command for my relay, may need to omit this. // there is a bunch of code here that is generic to the driver and not relay specific so the next change needs to happen at -> //sets relay private void SwitchOn() { if (connectedState) { byte[] relaycmd = new byte [4]; relaycmd[0] = startByte relaycmd[1] = relaynumber; // relay 1 relaycmd[2] = setpin; //byte for setting & next line is my best guess on what to do for the fourth character relaycmd[3] = setpin2; //byte for setting character 4 to A2 Serial.Write(relaycmd, 0, txtstringlen); // send command tl.LogMessage("SetSwitch", "0"); } } //reset relay code here. Same as above but clearpin and clearpin2
3 replies