Page 1 of 2

Serial Port. Com1 communication

Posted: Tue Jun 30, 2015 8:12 pm
by CPSEric
I would like to send some hexadecimal codes to a vending machine via the com port.
Does anyone have the syntax needed to do this?

So far what I have:

on MouseUp
open driver "COM1:"
<----- what goes in here to send the codes
close driver "COM1:"
end mouseUp

Any guidance would be deeply appreciated.

Re: Serial Port. Com1 communication

Posted: Wed Jul 01, 2015 5:22 pm
by jacque
Treat it as a file and use the write command.

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 5:05 pm
by CPSEric
Okay, I have been trying. This is what I have so far:
I think it should be working, but it is not.
Any more guidance?

on mouseUp
set the serialControlString to BAUD=38400, PARITY=N, DATA=8, STOP=1
open driver "Com1:" for binary write
write (0xFE, 0x08) to driver "Com1:"
end mouseUp

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 5:23 pm
by Klaus
Hi Eric,

some formal issues:
1. put QUOTES around strings!
...
set the serialControlString to "BAUD=38400, PARITY=N, DATA=8, STOP=1"
...
write "0xFE, 0x08" to driver "COM1:"
...
2. Check THE RESULT after opening the driver!
It will give you some info if and what might go wrong:

Code: Select all

...
## The dictionary uses capitals COM1, maybe that matters, too?
open driver "COM1:" for binary write
if the result <> EMPTY then
  anwer "ERROR:" && the result

  ## No need to proceed!
  exit to top
end if
...
Best

Klaus

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 6:19 pm
by CPSEric
Thank you so much for your response, I really appreciate it.

Went ahead and changed the code to:

on mouseUp
set the serialControlString to "BAUD=38400, PARITY=N, DATA=8, STOP=1"
open driver "COM1:" for binary write
write (0xFE, 0x08) to driver "COM1:"
end mouseUp

but it still did not work, it seems to behave like if the port was not open.

Any ideas?

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 6:57 pm
by Klaus
I may repeat mayself, but use QUOTES around strings:
...
write "0xFE, 0x08" to driver "COM1:"
...
and check the result! 8)

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 7:16 pm
by CPSEric
Sorry I missed that, but in all the tutorials I have read it has the content after the write command within parenthesis.

Made the change to:

on mouseUp
set the serialControlString to "BAUD=38400, PARITY=N, DATA=8, STOP=1"
open driver "COM1:" for binary update
write "0xFE, 0x08" to driver "COM1:"
end mouseUp

Still nothing.

I know all my connections are good, because if I send the command from Pololu Serial Transmitter it works.

I know this is something simple, but being a neophyte I must be missing it.

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 9:25 pm
by CPSEric
Serial communication is not dead, someone should have the answer. . . :-(

Anybody out there?

Re: Serial Port. Com1 communication

Posted: Wed Jul 08, 2015 10:24 pm
by Simon
I'd check this stack out
http://quality.runrev.com/show_bug.cgi?id=12545
Note there may still be a bug in LC 7.x but it seems they are getting it to work in 6.x

Simon

Re: Serial Port. Com1 communication

Posted: Thu Jul 09, 2015 2:42 pm
by CPSEric
Thank you Jacque, Klaus and Simon for trying to help me. This is so frustrating, I feel this is something simple to do, but for some reason it is just not working.

Went ahead and installed version 6, but that did not do it either.

I have a feeling that the code I came up with is not opening the port. What do you think?

If you get any other ideas, please let me know. Again THANK YOU so very much for your time and caring enough to help.

Eric

Re: Serial Port. Com1 communication

Posted: Thu Jul 09, 2015 3:54 pm
by Klaus
Hi Eric,

did I mention to check "the result" already? 8)

Code: Select all

...
## The dictionary uses capitals COM1, maybe that matters, too?
open driver "COM1:" for binary write
if the result <> EMPTY then
  anwer "ERROR:" && the result

  ## No need to proceed!
  exit to top
end if
...
might give a least a tiny hint.


Best

Klaus

Re: Serial Port. Com1 communication

Posted: Thu Jul 09, 2015 5:16 pm
by CPSEric
Actually, I installed version 6 and using this code:

on mouseUp
set the serialControlString to BAUD=38400, PARITY=N, DATA=8, STOP=1
open file COM1 for binary write
write "0xFE, 0x08" to file COM1
close file COM1
end mouseUp

With the above code I can at least see that the board I am trying to address gets a signal, by that I mean that I see communication. I think now it is a matter of sending the right hexadecimal command.

write "0xFE, 0x08" may not be correct. I don't know, but I am getting closer, I am seeing the diodes light up.

I also don't know what you mean by check the result other that it did not work.

Re: Serial Port. Com1 communication

Posted: Thu Jul 09, 2015 6:26 pm
by Simon
Hi CPSEric,
Before Klaus blows a gasket please look up "result" in the dictionary. You'll use it lots of times to help solve problems, it gives you messages as to possible problems.
Most of the time it's empty which means the last procedure worked.

Simon

Re: Serial Port. Com1 communication

Posted: Thu Jul 09, 2015 6:54 pm
by Klaus
Ommmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...

Thank you, Simon! :D

Re: Serial Port. Com1 communication

Posted: Thu Jul 09, 2015 7:30 pm
by CPSEric
I like what Simon says.

But please, let us not blow any gaskets. Klaus thank you too.

Is it Klaus Major? Have I not seen your name in several websites browsing for an answer to my dilemma?

Thank you all.