Friday, November 23, 2012

First contact!

It took me about 30 minutes to write a simple socket server application in C# but it took me FOREVER (OK, about 4 hours) to figure out how to configure the WiFly to talk back using socket.  Then it took me another FOREVER(again, about 4 hours) to figure out how to make the commands I am sending from C# app thru WiFly to CAN232 and retrieve the CAN data back from CAN232.


How to configure the WiFly:
Following was done using WiFlyClient app on my iPad.
[Edit] Just found out this can also be done using Terminal app on Mac.  telnet 169.254.1.1 2000
  1. $$$: put the WiFly into command mode 
  2. set comm close 0 (that is number zero)  : stop the module sending status message when network connection is closed.
  3. set comm open 0 (again, number zero): stop the module sending status message when network connection is open.
  4. set uart mode 0x10 (hex 10): clear all waiting data if connection is closed
  5. set uart baud 57600:  I have not tried it at 115200 but should work
  6. set sys printlvl 0 (again, number zero): stop misc status messages being sent to RS232
  7. set ip host ___.__.___ (my computer IP address here)
  8. set ip remote_port ____ (this just has to match my C# port)
  9. set sys autoconn 10
  10. save
  11. reboot
  12. cycle the power on the WiFly
Commands to send from C# app to CAN232:
  1. ""               // clear the buffer
  2. "C"            // close CAN232 just in case it was left open from previous
  3. "V"           // get CAN232 Version
  4. "N"           // get CAN232 Serial
  5. "S6"          // set the CAN bus speed to 500Kbit
  6. "M48000400"     // set acceptance code register
  7. "m31EFBBEF"  // set acceptance mask resister
  8. "O"                     // open the CAN channel

Sample data retrieved from CAN232:
t03A70000000024E247
t03E3173890
t0387C0000800000007
t03B5000E00EA38
t030884000000002000DC
t03A70000000024E247
t0203000007
t0387C0000800000007
t03A70000000024E348
t039429020F77
t0387C0000800000007
t03E3173890
t0387C0000800000007
t03B5000E00EA38
t039429020F77
t03A70000000024E247
t03E3173890
t0387C0000800000007
t3486000100000052
t030884000000002000DC
t0387C0000800000007
t0203000007
t022801FB01FC00000023

No comments:

Post a Comment