LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to write to custom hardware via serial communication ?

Is your string in normal display mode. Try changing your string to hex display and typing in the equivalent in hex 7F for 127 decimal.
0 Kudos
Message 11 of 44
(1,917 Views)
...OK I was too slowly...
0 Kudos
Message 12 of 44
(1,914 Views)

my hardware - well, it is A power line communication for the smart home....

transmitter connected to my pc via serial port, RS232.
a binary code sending from the pc to the transmitter, shipping the byte  on the power line , searching the receiver  with the same code ( mm53200 with a binary switch pin...)

in my old C program it was configured  com1, 300 baud, no parity, 8 bit data, 1 stop bit

it has an external power supply .

the data is a simple number, 1-127 and it is sending like a binary code...
127 = 1111111
15 = 0001111

while trying all the examples , didnt get any error  - and the hardware still not working .

sorry again for my english...:(


0 Kudos
Message 13 of 44
(1,923 Views)
Hi David and kingofnoland,
The content of the string remains the same no mather which format you display it. you should convert the binary number to string and than send it to the port. maybe that will work?

...no sorry I'm wrong my example does the same as you said, David...changing the view into hex and typing results in a hex format.

Message Edited by Olli on 01-04-2007 09:22 AM

0 Kudos
Message 14 of 44
(1,899 Views)
So this doesn't work ?
 
 
Can you post the c code? There might be a clue
Do you have any old screen shots of your C code in action?
 
Hey Olli, no worries. It was well worth mentioning. You can also use the typecast function for a straight U8 to string conversions.
 
David
 
 

Message Edited by David Crawford on 01-04-2007 03:33 PM

0 Kudos
Message 15 of 44
(1,888 Views)


@kingofnoland wrote:


in my old C program it was configured  com1, 300 baud, no parity, 8 bit data, 1 stop bit




If you are unable to connect to your machine properly, try restoring the default COM1 Properties (9600 baud, 8 data bits, no parity, 1 stop bit, no flow control) and then try and connect through Hyperterminal.  If you are unable to connect through Hyperterminal then we know there is a problem with your serial port or with your connection and can move foward from there.
0 Kudos
Message 16 of 44
(1,885 Views)
Are you sure that your computer's serial port will run at 300 baud? I am not sure about computers, but many other serial devices no longer run this slowly.

Lynn
0 Kudos
Message 17 of 44
(1,880 Views)
maybe some termination character needs to be attached to the data string, too  (like \n \s \r in codes display mode)?
0 Kudos
Message 18 of 44
(1,868 Views)
Thank u all for trying !
down listed is my C code .
David - nop, doesnt work
steve- try that along time ago.....
Olli - what are this termination character ?

The C code attached , hope it can help u to help me.


#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

#define com 1  /*use com1 */

void initCom(void)
{
    union REGS inregs, outregs;

    inregs.h.ah = 0; /* AH=0 - initilize comm port */
    inregs.h.al = 0x43; /* 300 baud, no parity, 8 bit data, 1 stop bit */
    inregs.x.dx = com - 1;  /* comm number: DX = 0 - com1, DX = 1 - com2 */
    int86(0x14, &inregs, &outregs); /*use bios interrupt */
    delay(200);
}

void send(char data)
{
    union REGS inregs, outregs;

    inregs.h.ah = 1; /* AH=1 - send character */
    inregs.h.al = data;
    inregs.x.dx = com - 1;  /* comm number: DX = 0 - com1, DX = 1 - com2 */
    int86(0x14, &inregs, &outregs); /*use bios interrupt */
    delay(200);
}

char receve(void)
{
    union REGS inregs, outregs;
    while (1) {
        inregs.h.ah = 2; /* AH=2 - receive character */
        inregs.x.dx = com - 1;  /* comm number: DX = 0 - com1, DX = 1 - com2 */
        int86(0x14, &inregs, &outregs); /*use bios interrupt */
        if (outregs.h.ah == 0)
            return(outregs.h.al);
    }
}






void main(void)
{                   /*Chars : R - reset the transmitter
                    /*        C - reset transmitter status
                    /*          T + reseiver address - toggle reseiver
                    /*        S - get status from transmitter (last operation)
                    /*          After S transmitter send byte to computer :
                    /*          D7 D6 D5 D4 D3 D2 D1 D0
                    /*        |  |  |  |  |  |  |  |
                    /*        |  |  |  |  |  |  |  relay status
                    /*        |  |  |  |  don't care
                    /*        |  |  |  unknown command
                    /*        |  |  timeout error
                    /*        |  busy write
                    /*        busy read*/
    unsigned char status;
    char address [10];
    int index;

    clrscr();
    initCom();   /*Initilize comm port
    send('R');   /*reset the transmitter
    send('S');   /*Get status from transmiter
    status = receve();
     printf("Status : %X \n", status);
    if (status == 0)
        printf(" transmitter ready\n");
    else {
        printf("transmiter not ready\n");
        exit(1);
    }

    printf("insert command -->");
    scanf("%s",address);

    send('T');  

    for (index = 0; index < strlen(address); ++index)
        send(address[index]);
    send(';');

    do {
        send('S');   /*Get status from transmiter */
        send(0xD);
        status = receve();
         printf("Status : %X \n", status);
        if ((status & 0x80) > 0)
            printf("standby...getting data\n");
        if ((status & 0x40) > 0)
            printf("standby...sending data\n");


        if ((status & 0x20) > 0) {
            printf("Success\n");
            exit(1);
        }
    } while ((status != 1) && (status != 0));
    if (status == 1) printf("Unit On\n");
    if (status == 0) printf("Unit Off\n");
}






0 Kudos
Message 19 of 44
(1,853 Views)
Hi kingofnoland,
some device need a termination character to recognise the end of byte you send. Common termination characters are \n (line feed), \r (carriage return) or \r\n (end of line) you can find them in string functions as constants or you type them in a string control/constant in "codes display" mode. It can be of course any other character. The devices I communicate with via serial port always need termination characters. I can't see directly a termination character within you c-code, but I'm not familiar with c.
Ciao,
Olli
0 Kudos
Message 20 of 44
(1,837 Views)