Hello Guest it is January 29, 2020, 02:46:43 AM

Author Topic: Making a connection through rs232 in Mach4  (Read 2319 times)

0 Members and 1 Guest are viewing this topic.

Re: Making a connection through rs232 in Mach4
« Reply #10 on: November 25, 2019, 08:59:51 PM »
Happy to help!

Looking great so far. Can you post a screenshot of your windows device manager showing COM4?

Also what version of Mach 4 are you using?

ALSO, I forgot. Can you post the entire LUA error message if you haven't fixed that yet?

Mike
« Last Edit: November 25, 2019, 09:02:31 PM by mcardoso »
Re: Making a connection through rs232 in Mach4
« Reply #11 on: November 25, 2019, 09:06:06 PM »
Attached.
any thoughts of what I might try next?
Also, If I wanted to change the baud rate or parity etc, I would just update the assert Statements right?

ex:
assert(p:set_baud_rate(rs232.RS232_BAUD_9600) == rs232.RS232_ERR_NOERROR)
Re: Making a connection through rs232 in Mach4
« Reply #12 on: November 25, 2019, 09:13:44 PM »
OK, two thoughts here.

First, 3804 is a little old for Mach 4. Couldn't hurt to install the latest. Maybe something has changed since then? Probably not, but thinking out loud.

Second (and maybe do this first), the returned error code "e" is a numerical value. It is 0 when there is no error and something else that we can use to troubleshoot the error.

Let'd modify your button code to say the following

Code: [Select]
mc.mcCntlSetLastError(inst, "Cannot Open Serial Port. Error: "..tostring(e))
That should print the error code number in the window and we can go from there.
Re: Making a connection through rs232 in Mach4
« Reply #13 on: November 25, 2019, 09:29:58 PM »
Preemptively, here are the error codes, extracted from the LUA source.

0=    { "RS232_ERR_NOERROR", RS232_ERR_NOERROR },
1=   { "RS232_ERR_UNKNOWN", RS232_ERR_UNKNOWN },
2=   { "RS232_ERR_OPEN", RS232_ERR_OPEN },
3=   { "RS232_ERR_CLOSE", RS232_ERR_CLOSE },
4=   { "RS232_ERR_FLUSH", RS232_ERR_FLUSH },
5=   { "RS232_ERR_CONFIG", RS232_ERR_CONFIG },
6=   { "RS232_ERR_READ", RS232_ERR_READ },
7=   { "RS232_ERR_WRITE", RS232_ERR_WRITE },
8=   { "RS232_ERR_SELECT", RS232_ERR_SELECT },
9=   { "RS232_ERR_TIMEOUT", RS232_ERR_TIMEOUT },
10=   { "RS232_ERR_IOCTL", RS232_ERR_IOCTL },
11=   { "RS232_ERR_PORT_CLOSED", RS232_ERR_PORT_CLOSED },
12=   { "RS232_ERR_BREAK", RS232_ERR_BREAK },
13=   { "RS232_ERR_FRAME", RS232_ERR_FRAME },
14=   { "RS232_ERR_PARITY", RS232_ERR_PARITY },
15=   { "RS232_ERR_RXOVERFLOW", RS232_ERR_RXOVERFLOW },
16=   { "RS232_ERR_OVERRUN", RS232_ERR_OVERRUN },

I entered the numbers by hand, but I'm pretty sure they are right.

Re: Making a connection through rs232 in Mach4
« Reply #14 on: November 25, 2019, 09:33:10 PM »
OK, Updated to Build 4300 and modified the error statement per your suggestion

It's spitting an error 2
Re: Making a connection through rs232 in Mach4
« Reply #15 on: November 25, 2019, 09:38:42 PM »
OK, So it is getting an error opening the port. Hmmmmm. Is this a USB port or a hardware RS232 port?

I don't see why you couldn't use a USB port or a USB->RS232 converter, however the PC I am using had a RS232 port embedded already so I stuck to using that.

It seems like you're doing everything right? I'm a bit stumped, but now very invested in getting this working!

I know you posted about it earlier, but can you double check that you don't have PuTTY or anything else open that might be using the serial port? I usually get this error when I leave my servo configuration software open and try to use Mach.
Re: Making a connection through rs232 in Mach4
« Reply #16 on: November 25, 2019, 09:40:40 PM »
Wait wait.
So, I clicked the button once and it didn't error. Like a fool I clicked it a second time and got the error... LOL
I think we're good.
 
I moved the code to the Screen load script and it "seems" to be working...?
Can you give me a code example of receiving data? I'm still misunderstanding how the luars232 works and how the letter "p" is defined and used.

thanks Mike!!!!
-Tim
Re: Making a connection through rs232 in Mach4
« Reply #17 on: November 25, 2019, 09:44:19 PM »
When I just tried to connect with Putty It got blocked!!!
I think we're golden

I just don't understand the "p" portion of the code you wrote,
Did you encapsulate the "p" functions  into a Lua Funtion inside the SheetLoad Script to use elsewhere?

I'm inches from the finish line here :)
-Tim
Re: Making a connection through rs232 in Mach4
« Reply #18 on: November 25, 2019, 09:47:40 PM »
Oh yeah:)

Once the port is open you aren't allowed to open it again!

Try a button on the screen with the code

Code: [Select]
p:write("Hello Arduino!\r")
Re: Making a connection through rs232 in Mach4
« Reply #19 on: November 25, 2019, 10:06:34 PM »
Nothing, But I don't have anything setup on the Arduino side to see and I'm not reading the buffer on that side (Nothing errored in Mach BTW)

Would you mind maybe giving me an example that reads "Hello World" from the buffer and Spits it out to a label "testLabel"
I tried this in the button with no luck (Lua Chunk error)
e = p:flush()
scr.SetProperty("testLabel","Label",p:read(12, 5))

Sooo close...
thanks -Tim