Solved

Send byte record to RS232, Microcontroller

Posted on 2008-10-24
5
1,174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
Moving your enterprise fax infrastructure from in-house fax machines and servers to the cloud makes sense — from both an efficiency and productivity standpoint. But does migrating to a cloud fax solution mean you will no longer be able to send or re…
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.

732 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