Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Asynchronous Serial Communication


  • Please log in to reply
1 reply to this topic

#1 JimmyFR

JimmyFR
  • Members
  • 1 posts

Posted 18 March 2013 - 03:53 AM

Hello I wish to realize one to schedule(program) allowing me to test the performances of the labjack U3. I wish to send one any datum for the intermediary of a TEdit and I wish to post(show) him(it) in a TLabel. I do not manage to get back the value in the TEdit and my compiler declare myself one error at the level of my declaration long array[32]; (unable to convert long* in long). Here is my code : //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #define buffsize 5000 #include "Unit1.h" #include <iostream> #include "debug_console.h" #include <stdio.h> #include <stdlib.h> #pragma link "libLabjackUD.lib" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { lngHandle = 0; } //--------------------------------------------------------------------------- //This is our simple error handling function that is called after every UD //function call. This function displays the errorcode and string description //of the error. It also has a line number input that can be used with the //macro __LINE__ to display the line number in source code that called the //error handler. It also has an iteration input is useful when processing //results in a loop (getfirst/getnext). void ErrorHandler( LJ_ERROR lngErrorcode, long lngLineNumber, long lngIteration =0 ) { char err[255]; if( lngErrorcode != LJE_NOERROR ) { ErrorToString( lngErrorcode, err ); WriteLn( String().sprintf("Error number = %d", lngErrorcode) ); WriteLn( String().sprintf("Error string = %s", err) ); WriteLn( String().sprintf("Source line number = %d", lngLineNumber) ); WriteLn( String().sprintf("Iteration = %d\n", lngIteration) ); // if(lngErrorcode > LJE_MIN_GROUP_ERROR) // { // //Quit if this is a group error. // exit(0); // } } } void __fastcall TForm1::Button3Click(TObject *Sender) { try{ LJ_ERROR lngErrorcode; long lngTemp = 0; double dblTemp = 0; //Open the first found LabJack U3. lngErrorcode = OpenLabJack( LJ_dtU3, LJ_ctUSB, "1", 1, &lngHandle ); ErrorHandler(lngErrorcode, __LINE__); // Configure the UART communication: // TX and RX appear after all timers and counter. // We wont have any timers/counters but we will have an offset // of two, putting TX on FIO2 and RX on FIO3. lngErrorcode = ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 2, 0); ErrorHandler(lngErrorcode, __LINE__); //Set data rate for 9600 bps communication. lngErrorcode = ePut(lngHandle, LJ_ioPUT_CONFIG, LJ_chASYNCH_BAUDFACTOR, 65224, 0); ErrorHandler(lngErrorcode, __LINE__); //Enable UART. lngErrorcode = ePut(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_ENABLE, 1, 0); ErrorHandler(lngErrorcode, __LINE__); if( lngErrorcode == LJE_NOERROR ) Button2->Enabled = true; else return; lngGetNextIteration = 0; //Used by the error handling function. while( lngErrorcode < LJE_MIN_GROUP_ERROR ) { lngErrorcode = GetNextResult( lngHandle, &lngIOType, &lngChannel, &dblValue, &lngTemp, &dblTemp ); if( lngErrorcode != LJE_NO_MORE_DATA_AVAILABLE ) ErrorHandler( lngErrorcode, __LINE__, lngGetNextIteration++ ); } WriteLn( "'Connect' terminé" ); //5 } catch(...) { WriteLn( "Erreur dans 'Connect'" ); } } void __fastcall TForm1::Button1Click(TObject *Sender) { LJ_ERROR lngErrorcode; double numBytes = 3; long array[32]; lngErrorcode = eGet(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_TX, &numBytes, array); ErrorHandler(lngErrorcode, __LINE__); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { LJ_ERROR lngErrorcode; double numBytes = 3; long array[32]; char var[200]; lngErrorcode = eGet(lngHandle, LJ_ioASYNCH_COMMUNICATION, LJ_chASYNCH_RX, &numBytes, array); ErrorHandler(lngErrorcode, __LINE__); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::EnableButton(TObject *Sender, char &Key) { Button1->Enabled = true; } //--------------------------------------------------------------------------- Thank for all

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 March 2013 - 07:22 AM

Seems like the compiler error is the first problem to address. What programming language and OS is this?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users