CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 1999
    Posts
    3

    Sending a string out port 1



    Could someone please tell me the code needed to send out the ascii value of a CString class variable out port 1?

  2. #2
    Join Date
    Mar 1999
    Posts
    8

    Re: Sending a string out port 1



    Include the MS Commnication control to your object.Create the control in one of

    your classes. Use the memeber function for outputting the string to the any of the COM

    port.



  3. #3
    Join Date
    Apr 1999
    Location
    Delhi, India
    Posts
    32

    Re: Sending a string out port 1

    I am able to send a CString all right. But I want to send an array of BYTES :
    unsigned char arr[100];
    I am able to send this through the Com port using MSComm control. But at the receiving end, I am stuck. The incoming array is available wrapped inside a VARIANT. How to extract my array from within this variant ? Should I use a SafeArray ?
    I'm not sure how to convert the variant to SafeArray.
    Please help me with a piece of code, if possible.
    Thanks.


    nikku

  4. #4
    Guest

    Re: Sending a string out port 1

    nikku

    The return type is a VARIANT. The vt field (VARTYPE) should be equal to 0x2011 and the parray field data is a pointer to a SAFEARRAY that contains the data.
    To find out how many bytes have been received from the port you could do the following:
    VARIANT varg;
    varg = MSCommObj.GetOutput();
    if(varg.vt != 0x2011) // don't know if this absolutely correct!!!
    continue;
    number of bytes read from COM1 = varg.parray->rgsabound[0].cElements
    ptr to array of bytes read = varg.parray->pvData

    Kevin M. Reilly



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured