Solved

Send byte record to RS232, Microcontroller

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Upper back Pain: My back hurt for months. Upper back, mostly my neck, spine and across my shoulder blades. I was getting headaches too, that felt like they were caused by tension in my shoulders, but now I feel fine! I'm sharing this hoping someone…
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

911 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

20 Experts available now in Live!

Get 1:1 Help Now