May i know how to sent byte array to serial port using maxscript?

May i know how to sent byte array to serial port using maxscript?

Anonymous
Not applicable
939 Views
2 Replies
Message 1 of 3

May i know how to sent byte array to serial port using maxscript?

Anonymous
Not applicable
May i know how to sent byte array to serial port using maxscript?
I have a device which requires me to sent data through serial port. In order to achieve serial communication i use dotnet object SerialPort.Write (Byte(), Int32, Int32) to sent my data but i have no idea how to sent byte array (byte()) in maxscript, can anyone tell me how?


port = dotNetObject "System.IO.Ports.SerialPort"
port.portname = "COM1"
port.baudrate = 2400
port.parity = port.parity.none
port.databits = 8
port.stopbits = port.stopbits.one
port.handshake= port.handshake.RequestToSend


try (destroyDialog rol_ServoCOMM) catch()
rollout rol_ServoCOMM "Servo Communication" width:500 height:600

(
button btn1 "Connect COM 1"
on btn1 pressed do
(
port.open()
)


button btn10 "array servo2"
on btn10 pressed do
(
command=16
position=100
arr00=#(command,position)
port.write(arr00,0,2)
)


)
createDialog rol_ServoCOMM


I'm sending 2 bytes data through method
port.write(buffer As Byte(), offset As Integer,count As Integer)

P.S. When i run this script the error dialog as followed:

>> MAXScript FileIn Exception: -- Syntax error: at ),, expected <factor>
-- In line: port.write(arr00,0 <<
0 Likes
940 Views
2 Replies
Replies (2)
Message 2 of 3

Steve_Curley
Mentor
Mentor
Tip. Be very careful with angle brackets on this forum - it tends to eat them unless within a code block. I edited them into your post as part of the error message was "missing".

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 3

Anonymous
Not applicable
I found the error!

it's that i have to write like this:

port.write arr00 0 2


instead of the bracket.

Now i can initiate data sending but the format seems to be incorrect (SerialPort.Write (Byte(), Int32, Int32))

I just installed 3ds max 2010 last night and i found that i can easily create byte array byte() using the following code:

type = dotNetClass "System.byte[]"
res = dotnet.ValueToDotNetObject #(16,50) type

But the "res" created here is a dotnetobject, how i change it back to value?
I have to put "res" into port.write res 0 2 but since "res" is a dotnetobject it show argument error. how to put it in as the value?

type = dotNetClass "System.byte[]"
res = dotnet.ValueToDotNetObject #(16,50) type
port.write res 0 2
0 Likes