Sending bytes to Serial module

Share your scripts written for the Script Device in this forum.
Post Reply
martijnj
Member
Posts: 61
Joined: Mon Nov 03, 2003 2:50 pm
Location: NL

Sending bytes to Serial module

Post 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.
Attachments
Handbuch.pdf
(360.1 KiB) Downloaded 327 times
martijnj
Member
Posts: 61
Joined: Mon Nov 03, 2003 2:50 pm
Location: NL

Re: Sending bytes to Serial module

Post 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
Post Reply