Serial Port. Com1 communication

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Serial Port. Com1 communication

Post by CPSEric » Tue Jun 30, 2015 8:12 pm

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Serial Port. Com1 communication

Post by jacque » Wed Jul 01, 2015 5:22 pm

Treat it as a file and use the write command.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Wed Jul 08, 2015 5:05 pm

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Serial Port. Com1 communication

Post by Klaus » Wed Jul 08, 2015 5:23 pm

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

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Wed Jul 08, 2015 6:19 pm

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?

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Serial Port. Com1 communication

Post by Klaus » Wed Jul 08, 2015 6:57 pm

I may repeat mayself, but use QUOTES around strings:
...
write "0xFE, 0x08" to driver "COM1:"
...
and check the result! 8)

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Wed Jul 08, 2015 7:16 pm

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.

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Wed Jul 08, 2015 9:25 pm

Serial communication is not dead, someone should have the answer. . . :-(

Anybody out there?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Serial Port. Com1 communication

Post by Simon » Wed Jul 08, 2015 10:24 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Thu Jul 09, 2015 2:42 pm

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Serial Port. Com1 communication

Post by Klaus » Thu Jul 09, 2015 3:54 pm

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

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Thu Jul 09, 2015 5:16 pm

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Serial Port. Com1 communication

Post by Simon » Thu Jul 09, 2015 6:26 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Serial Port. Com1 communication

Post by Klaus » Thu Jul 09, 2015 6:54 pm

Ommmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...

Thank you, Simon! :D

CPSEric
Posts: 11
Joined: Tue Jun 30, 2015 4:23 pm

Re: Serial Port. Com1 communication

Post by CPSEric » Thu Jul 09, 2015 7:30 pm

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.

Post Reply

Return to “Windows”