C
C#13mo ago
Gregory

❔ 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
2 Replies
Gregory
Gregory13mo ago
had this all written out and didn't realize there was a character limit. Basically trying to edit this C# ASCOM code to work with my relay. This was written for a KMtronic relay and I have a CH340 relay that requires 4 characters to control. I have little knowledge in C# but this is my best guess on how to edit the code. The source also has relay status check coding but I cannot for the life of me find the character that checks my relay. I'm not sure it exists so may need to get rid of that portion of code.
Accord
Accord13mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.