Solved

Send byte record to RS232, Microcontroller

Posted on 2008-10-24
5
1,170 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DVD BURNER 2 44
Locked BIOS on HP laptop 9 59
S1200BTL Rack Mount Case 4 44
assignment of laptops - risks 6 84
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.
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
The viewer will learn how to use and create keystrokes 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.

713 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