• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

Perl programming - generating packets

vthinsel

New member
Hello !

I'm still trying to make my 635 work with perl.
I'm able to get keypad press from my scripts, and it works OK. The hex I get back is fine. So basically, I'm able to receive packets from 635.
The problem I have is to push packets to 635.

First point: I'd like to be sure my test packets are valid:
ping packet: 0x00 0x01 0xff 0xD0 0x6C
contrast to 10: 0x0D 0x01 0x0A 0x8F 0x31
contrast to 95: 0x0D 0x01 0x5F 0x8A 0x19

Should those packets be understood by 635 ?

Second point: I also suspect my port settings to be wrong. I grabbed the settings from the port when it was opened by your demo program. Would someone have a short sample script that outputs something on a 635, in perl under linux (or even windows) ?

I had no problems making the 634 (both serial and early USB) work. The 635 is hard to get to work. My perl is also quite far away...

Thanks.

Vincent
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

CF Mark

Administrator
Your ping packet is correct.

Your contrast packets are also correct, but remember the value for contrast is not a percentage like the brightness value.
The contrast value is 0 to 255.

Im not sure about the port settings, i have only done very basic perl programming before.
 

vthinsel

New member
CrystalControl Admin said:
Your ping packet is correct.

Your contrast packets are also correct, but remember the value for contrast is not a percentage like the brightness value.
The contrast value is 0 to 255.

Im not sure about the port settings, i have only done very basic perl programming before.
Now I know I have a working packet generator in perl. I just need to find how to push them correctly. I'm able to read ! It shouldn't be that difficult to write !! I'm really hopeless in perl.

Thanks for your response.
 

vthinsel

New member
Some fresh update.
The best sites I have found on internet are:
http://members.aol.com/Bbirthisel/alpha.html
http://members.aol.com/Bbirthisel/tpj_serialport.d/index.html
and http://aplawrence.com/Unix/logger.html (probably based on previous links).
Using all this, I was able once more to get packets for KP, but still unable to send anything. What is very strange is that just after sending a packet, I don't get anything back as if nothing was sent. The only packets I get back are the KP events.
This is weird.
The port settings I use are OK, otherwise I wouldn't receive anything back.
Do you know how to "snoop" the serial port ? This is the only option I see now to make sure something goes to the 635.

Thanks.

Vincent
 

CF Tech

Administrator
We have a utility that can be used to snoop for packets. It runs under Windows. You would need to make a four-headed cable, two are pass-through of the connection under inspection, two additional connections go to the two serial ports of the snooping machine (one listens to Tx, one listens to Rx of the connection under inspection.

Please write support(at]crystalfontz[dot}com (edit to '@' & '.') and we can give you the program. You can make the cable, or we can supply a cable (though it is a bit spendy :( ).
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

vthinsel

New member
Hello again !

I GOT IT ! It finally works....
2 things were wrong/missing:
1) The CRC calculation: the byte order is swapped is my previous post. Sending those packets was of no use. How did I come to this result ? I used a marvellous software to snoop the serial port: http://www.serial-port-monitor.com/index.html
Then I used 635_WinTest_1_0.exe and sent a ping packet with one byte of data with 0xFF, as in my first post. And then, I got a big surprise:



The first exchange is the WinTest one. The CRC for the ping packet is 6C D0. Mine was D0 6C, as show in the second example. And this doesn't trigger a response packet from the 635. I was expecting a message saying the packet was corrupted. I'll read the specs better next time. So I swapped the byte order in my code, and then it worked as show in the third exchange.

2) At the beginning, I couldn't get the packet back with my app. This was just due to a "sleep 1" missing, so the 635 had enough time to answer. He is fast, but not as my PC :)

So I have now some working perl code, working both in windows and linux. Yes, I'm more of a linux guy but as I couldn't find an app to snoop the port under linux, I decided to switch to windows. So why not having a portable perl code ?

The following calls:
print "Sending ping packet: ".str2hex(genpkt(0x00,pack 'C',0xff))."\n";
$result=sendpkt($ob,genpkt(0x00,pack 'C',0xff)); #ping packet
print "Result:".str2hex($result)."\n";
print "Sending version packet: ".str2hex(genpkt(0x01,''))."\n";
$result=sendpkt($ob,genpkt(0x01,'')); #get version packet
print "Result in hex:".str2hex($result)."\n";
print "Result in str:".($result)."\n";


Produced:


G:\lcdlib\TestsStandalone>serial6.pl
baud from configuration: 115200
Sending ping packet: 00 01 ff 6c d0
Result:40 01 ff 1a d6
Sending version packet: 01 00 9f 16
Result in hex:41 10 43 46 41 36 33 35 3a 68 31 2e 30 2c 76 31 2e 34 63 a2
Result in str:A?CFA635:h1.0,v1.4có



For now, I'll clean a bit the code and I'll post it here. I couldn't wait to send this post, as I provide an answer, for once.

Thanks for supporting my annoying posts, but it helps me to write :)

See ya !
 

CF Tech

Administrator
Hey, I am glad you got it working. I am sure your post will be useful to other users who wish to use PERL to communicate with the LCD.
 

vthinsel

New member
Working perl code for 635, at last.

So, here we are.

I have attached the perl code.
It currently allows you to send commands by giving the type and the arguments, it reads data back from 635, you can configure retries and delay, it unserializes the data (not very efficiently, but it works), and it can decode the keypad as well.
And it works both on linux and windows (one limitation though, on windows: as there is no usleep, it waits 1 second for incoming packets).

If someone can test this, or optimize it, I'll be glad to get feedbacks.

Now I'll work on the complete library function. It is a shame I didn't think to get the SCAB, so I'll blind code this. Maybe someone can test it later.

Vincent.
 

Attachments

itisnt

New member
Hi

Thanks a lot for your Code.

I've changed and extended the Code to
have a more flexible Skeleton for
other Programs.
I've also added some new Functions:

- Playing around with the four LED's at the
left side
- Set Coursor Style
- Set Key Report Mask
- Set Backlight
- Set Contrast

Daniel
 

mchineboy

New member
POE Event Driven Interface

I've further updated this script to use the POE module in perl.

Currently, it displays the current date/time, current load, and the cpu usage of the perl program. It also "heartbeats" the 4th LED to let you know that it's alive. :)

So far it works. Should be fairly easy now to attach multiple screens and such :)

Just remeber to point it at the proper serial port that the LCD is attached to.
 

Attachments

Top