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
Solved

Send byte record to RS232, Microcontroller

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

In this article you will get to know about pros and cons of storage drives HDD, SSD and SSHD.
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

829 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