Page 1 of 1

Sending bytes to Serial module

Posted: Tue May 09, 2023 6:47 pm
by martijnj
Can sombody help me with this.

I want to send the result of the following code to a serial device (8xrelay) over the generic serial module.

Code: Select all

outbuf0 = 3
outbuf1 = 0
outbuf2 = 0
outbuf3 = outbuf0 Xor outbuf1 Xor outbuf2
Result = outbuf0 & " " & outbuf1 & " " & outbuf2 & " " & outbuf3

SetPropertyValue "Relays.Relay Commando", Result
This works fine until the outbuf2 value reaches 11

On the serial monitor the data then is 003 001 011 009'

When the value of outbuf is 12 the data reads 003 001 001 002 014. The 12 gets split in 001 and 002.

Why is the happening with the outbuf2 and not with the outbuf3.

I hope that someone can explain this to me please.

As attachment the info of the device.

Re: Sending bytes to Serial module

Posted: Wed May 10, 2023 8:08 am
by martijnj
'solved'

Code: Select all

'init
Output = SendCommand (1,0,0)
'Send Command
Output = SendCommand (3,0,RelayCode)

Function SendCommand (Commandbyte, Adressbyte, Databyte)

	CheckSum = Commandbyte Xor Adressbyte Xor Databyte
	If Commandbyte = 0 Then 
		SetPropertyValue "Relays.RelayHex", Commandbyte
	Else
		SetPropertyValue "Relays.Relay Commando", chr(Commandbyte)
	End IF
	If Adressbyte = 0 Then 
		SetPropertyValue "Relays.RelayHex", Adressbyte
	Else
		SetPropertyValue "Relays.Relay Commando", chr(Adressbyte)
	End IF
	If Databyte = 0 Then 
		SetPropertyValue "Relays.RelayHex", Databyte
	Else
		SetPropertyValue "Relays.Relay Commando", chr(Databyte)
	End IF
	If CheckSum = 0 Then 
		SetPropertyValue "Relays.RelayHex", CheckSum
	Else
		SetPropertyValue "Relays.Relay Commando", chr(CheckSum)
	End IF
END Function