LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

device card

right so i can do it both ways

 

static char COM[6] = "COM10";

 

    bytes_sent= OpenComConfig(COMPORT,COM,BAUDRATE,PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);

*******************************

 

 

my question is to do it your way, how its going to know to talk to COM10

0 Kudos
Message 41 of 80
(3,142 Views)

Leave the Device Name blank (forgive me if I'm repeating myself and echoing Roberto!) and set the COM Port to 10.

 

device_err = OpenComConfig(10,"",BAUDRATE,PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);

 

That assumes that your RS-232 card and device driver are installed properly for you to talk to COM10.  As Roberto asked, do you have any test program for your RS-232 card?

0 Kudos
Message 42 of 80
(3,144 Views)

Darnell:

 

I'd like to respond to something you said earlier in this post.

 

"before i post anything in the forum .trust and believe I have tried everything there is. so then i ask question not for people to my work, because i have already done the work.

 

How does it help you if we believe that you have tried everything there is?  It's obvious to any experienced programmer that you have not tried everything.  If you had "tried everything there is" than your problem would, in fact, have no solution.  The other possibility is that there are some things you haven't tried, and we're here to help point you to some of them.

 

It's ok to ask for help.  Every programmer needs help from time to time.  But when you ask for help, you need to carefully read the answers and respond directly to the questions we ask.  Roberto has pointed that out to you in this post.  I have done the same in other posts of yours.

 

As Roberto and I have also pointed out, you often jump on to the next question without any acknowledgement of previous answers given.  Of all the many questions you have posted, you have identified only one as having a solution.  Of all the work others have done for you, none has rated a Kudo from you.  Is that because you have "already done the work"?  Who are you trying to convince of that?  We see some of the code we have posted for you show up in subsequent posts.  I'm glad if any of my posts have helped you, and you are free to use any of the code I have posted.  But if you have already done the work and have tried everything there is, why do you need help?

 

I have already suggested that you get a good C reference book and have offered some suggestions of titles from my bookshelf.  I was going to suggest that you go back to school and enroll in a basic programming class, but based on the multiple posts in various subjects that you have posted on other websites, it looks like you are already a student.  Do you have the textbook?  Can you make an appointment with your professor or grad assistant?  If you have over-sold your programming experience (as you seem to do here) to get into an advanced programming class, it looks like you're in over your head.  Talk to your professor or advisor about taking a step back and enrolling in an introductory programming class.

 

As a student or a programmer, your goal should be to learn anything you need to get the job (or class project) done.  We're here to help, but we can't replace the good foundation you should receive in a classroom setting or by working through examples and tutorials on your own.  I never had a class on C, but I studied and worked on my own, starting with the classic "Hello World!" program.  If you're in a class now, you're not getting your money's worth.

 

I remember a time when I didn't know a pointer from a sharp stick, so I'm trying not to be too critical.  I started with the basic fundamentals, and you need to, too.

Message 43 of 80
(3,143 Views)

im not that slow in programming. i already know that stuff. I ask alot of stupid questions because i second guest myself alot. which i need to stop becuase when i

 

do that i throw you off everytime, and make you think that i dont know programming. so i will stop asking the fundamental question even though i already know

 

okkkkkkkk Al s. thanks

0 Kudos
Message 44 of 80
(3,140 Views)

also for the COM10

 

 

in our device manager we have two ports  that are port 1.

 

 

 

the first one  is port 1 COM1

 

the second one is port 1 COM10

 

 

so thats why i was going it that way.

 

so you saying just do it this way and then it would work.

 

in the help menu, its says that when you want to use a comport above 4,windows  treat it differently

0 Kudos
Message 45 of 80
(3,138 Views)

Did you try what I suggested earlier?  What were the results?

 

device_err = OpenComConfig(10,"",BAUDRATE,PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);

 

0 Kudos
Message 46 of 80
(3,134 Views)

#define COMPORT 10   

device_err= OpenComConfig(COMPORT,"",BAUDRATE,PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);

 

 

i did it your way, it works now. Im havent test it on the instrument yet  so im getting ready to go to the lab to find out if it work or not.

 

 

im out of school. 

 

this is not the first time i have talk to an instrument.I do it all the time. now it is my first time using RS232 and also formatting address through binary

 

. im normally just pointing the ip address. buts its a good thing because i have a learn alot.

 

im at c++ .net person, i didnt start from the basic C programming. 

 

Its really a big difference from c++ .net to the basic C language.

0 Kudos
Message 47 of 80
(3,135 Views)
also im not using your code. because i have to other stuff. now i would your code is similiar towhat im doing. but like i said before i only ask stupid question when i can get the instrument to respond. so thats when i go back and start double checking my self by asking you guys to see if you coming up with the same thing . thats my way of knowing thats it a hardware issue or cabling issue. becuase if we both are doing the same thing. then something is wrong else wise.
0 Kudos
Message 48 of 80
(3,133 Views)

ok , for some reason today when we were scoping to see what we were sending out, all of my bits were reverse.

 

so say for instance if i set outputdata[4]=1;

 

on the scope machine it would send out 1000000 instead of 00000001.

 

so that could be an issue. also on the scope machine we kept seeing extra bits ,  it would throw in a 1 0, so everytime the 1 0, i would se my next element of the array.

 

so i dont know whats thats all about.

 

then also my element [6] wasnt the correct sum, so im going to try one more thing and then say its a hardware issue. but you can assist me if you want.

 

****************************************

 

#include <ansi_c.h>
#include <visa.h>
#include <userint.h>
#include <rs232.h>
#include <utility.h>
#include <stdio.h>
#include "visa.h"


#define MSCARD_BYTE        0x00
#define NUM_ADDRESS_BITS   0x5
#define    NUM_BYTE_IN_CMD    0x7
#define NUM_BYTE_IN_RESP   0x7
   
#define SEND_CHKSUM_BYTE   0x6
#define RECORD_CHKSUM_BYTE 0x2
#define REC_BUSERROR_BYTE  0x3
                                       
#define TEXT_LENGTH        2000

#define COMPORT            10
#define BAUDRATE           115200
#define DATABITS           8
#define PARITY             0
#define STOPBITS           1
#define INPUTQ             512
#define OUTPUTQ            512
#define STRINGSIZE         7

int MASTER_RESET_UPDATE_DEVICE ( int CommandCode,int deviceAddress, int data );



//static char COM[6] = "COM10\0";
unsigned char   outputdata[NUM_BYTE_IN_CMD];
unsigned char    inbuff    [NUM_BYTE_IN_RESP];


int bytes_sent=0;
int bytes_read=0;

  
char read_data[TEXT_LENGTH];

int main()
{

    //    MASTER_RESET_UPDATE_DEVICE('R',0,0);
           
        MASTER_RESET_UPDATE_DEVICE('U',0x1,0xFA);
   

   
       
        return 0;


}

int MASTER_RESET_UPDATE_DEVICE (int CommandCode, int deviceAddress, int data )

{   
    int device_err;
    int msblsb=0;
    int MSCardAddress=0;
      //  CommandCode='U';
      // deviceAddress=0x1;
      //  data=0xFA;
   
    device_err= OpenComConfig(COMPORT,"",BAUDRATE,PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);
   
    memset( outputdata, 0, NUM_BYTE_IN_CMD);
    memset( inbuff,     0, NUM_BYTE_IN_RESP);   
   
  outputdata[MSCARD_BYTE] = MSCardAddress;
    outputdata[1] = CommandCode; //'U';
   
    // embed controller number and device address into output message

    /*data <<= NUM_ADDRESS_BITS; // left shift data bits
    msblsb = data | deviceAddress;  // combine data and address bits
    outputdata[2] = (msblsb>>8) & 0xff;  // Set MSB
    outputdata[3] =  msblsb & 0xff;  // Set LSB

    outputdata[4];
    outputdata[5];
    // calc check sum
   

outputdata[6] = outputdata[0] + outputdata[1] + outputdata[2] + outputdata[3] +outputdata[4]+ outputdata[5];
    outputdata[6] = outputdata[6] & 0xFA; 

    bytes_sent=ComWrt(COMPORT,outputdata,NUM_BYTE_IN_CMD);
   
    Delay(0.5);

    bytes_read=ComRd(COMPORT,inbuff,NUM_BYTE_IN_CMD);
   
        if (bytes_read != NUM_BYTE_IN_CMD)   
    {
        MessagePopup("%s","NOT READING ANYTHING, CHECK HARDWAREV!!");
       
    } */

   
        // Get response from COM device

        if (bytes_sent != NUM_BYTE_IN_CMD)   
    {
        MessagePopup("%s","CAN'T WRITE TO DEVICE, CHECK COMPORT SETTINGS!!");
       
    }

    // Get response from COM device

       
    // compare card Address bytes
    if (outputdata[MSCARD_BYTE] != inbuff[MSCARD_BYTE])
       
    {
                MessagePopup("%s","CHECK CARD ADDRESS!!");
    }
       
       // compare checksum bytes
    if (outputdata[SEND_CHKSUM_BYTE] != inbuff[RECORD_CHKSUM_BYTE])
    {
        MessagePopup("%s","CHECK SUM BYTE NOT EQUAL!!");
    }
    // Check returned status byte
    if (inbuff[REC_BUSERROR_BYTE] == 0)   
    {
        return VI_SUCCESS;
    }

return 0;   
       

}
   
 

0 Kudos
Message 49 of 80
(3,103 Views)

What you are seeing on the oscilloscope is normal RS232 protocol.

 

RS-232 uses reverse logic.  The higher voltage is a logic 0, and the lower voltage is a logic 1.

 

If you are looking at an RS232 bitstream on an oscilloscope, you need to realize that in the RS232 protocol, the least significant bit (lsb) is sent first, and the most significant bit (msb) is sent last.  So if you transmit a 1, then 1 will be the first bit sent, and it's easy to think that your bits are reversed.  It doesn't matter that you see them "backwards": the receiving UART will correctly interpret them.  A 1 sent = a 1 received, not 10000000.

 

The other thing you need to know about RS232 is that it is asynchronous, meaning that the length of time between bytes in indeterminate: you don't know how long it will be.  So there needs to be a way to tell the receiver that the next byte is coming.  The way it does this is by using a start bit.  The signal is 1 when idle (between bytes).  When the next byte is sent, it always starts with a 1-bit-wide start bit, which is a logic 0.  This bit is not part of your data: it is just used to tell the receiver that another byte is coming.

 

The way the UART parses bits is by sampling the signal at a known baud rate after it receives the start bit.  Most UARTs sample each bit 16 times, and use the middle 3 samples as the indication of bit value.

 

Stop bits are at a logic 1.  They are not part of your data, but the number of stop bits is an agreement between the transmitter and the receiver about the minimum time between bytes.  Since you are configuring the COM port to use 1 stop bit, you know that there is at least one bit time where the signal will be a logic 1 before the next byte can be transmitted.

  

Look at this Wikipedia article for more info on RS232.  In the section titled Voltage Levels, there is a nice picture of what you would see on a scope for a particular byte written.

http://en.wikipedia.org/wiki/Rs232 

 

In terms of the scope setup, 1 bit time at 115200 baud = 1/115200 = 8.68 uS.  Set the scope to 10 uS per division.

Set the trigger to be rising edge at 3 VDC.  You may have to play with the voltage level of the trigger: The RS232 standard allows a pretty wide voltage swing.  Set the trigger to Normal (not automatic).  Send one byte.  Your trigger should be on the rising edge of the start bit.  Use the scopes cursors to count bit times of 8.68 uS, remembering that the signal is displayed from lsb to msb from left to right.

0 Kudos
Message 50 of 80
(3,095 Views)