Solved

Send byte record to RS232, Microcontroller

Posted on 2008-10-24
5
1,159 Views
Last Modified: 2013-11-23
Hello!

I have a Luminary Micro Controller where all code examples are written in C.
From their support I've been told that I need to open a COM port in Delphi and
send a packet of bytes to the microcontroller.

  The C packet looks like this:
   //
    // Construct a set target position command.
    //
    g_pucData[0] = TAG_CMD;
    g_pucData[1] = 0x09;
    g_pucData[2] = CMD_SET_PARAM_VALUE;
    g_pucData[3] = PARAM_TARGET_POS;
    g_pucData[4] = g_ulTargetPosition & 0xff;
    g_pucData[5] = (g_ ulTargetPosition >> 8) & 0xff;
    g_pucData[6] = (g_ ulTargetPosition >> 16) & 0xff;
    g_pucData[7] = (g_ ulTargetPosition >> 24) & 0xff;
    g_pucData[8] = {checksum};

Bytes in the packet should be:
0xFF 0x09 0x13 0x08 0x00 0xC8 0x00 0x00 0x13

In Delphi I'm using a component called TSerialPortNG to open the COM port (COM3) and send data.
procedure SendData(Data: Pointer; Size: Cardinal);

Need help to define the Delphi/pascal record and add the byte values to it before sending.

Many thanks,

-B
0
Comment
Question by:MrSimpson
  • 4
5 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
ID: 22801018
var
  pack: packed array[0..8] of byte;
  p: pointer;
begin
  pack[0] := $FF;
  pack[1] := $09;
// and so on
  p := @pack;
0
 

Author Comment

by:MrSimpson
ID: 22802038
I belive this is correct, however nothing happends when I send the packet,
(It is supposed to run a stepper motor).
Maybe the TAG_CMD etc. should be text (string)?
0
 

Author Comment

by:MrSimpson
ID: 22802296
I'm monitoring the port while running a application that comes with the board and are able to
get all the bytes sent.
When I'm sending a packet, only 4 bytes are sent. (FF 09 13 08).

It seems that the other application is sending 3 packets to have the motor running:
(the second byte tells the length of the packet)
FF 09 13 08 00 F4 01 00 E8
FF 04 30 CD
FF 09 13 08 00 F4 01 00 E8




0
 

Author Comment

by:MrSimpson
ID: 22802991
My fault.
I wrote: SendData(p, SizeOf(p));
Should have been: SendData(p, SizeOf(pack));

Many thanks Mokule!




0
 

Author Closing Comment

by:MrSimpson
ID: 31509858
Thank you very much mokule!
Was able to monitor all packets sent from the other application and sent the same from mine! :O)

Regards.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What do we know about Legacy Video Conferencing? - Full IT support needed! - Complicated systems at outrageous prices! - Intense training required! Highfive believes we need to embrace a new alternative.
In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now