Charlie2134 Posted August 15, 2023 Share Posted August 15, 2023 Hello, I don't know how to output and measure the analog input signals at the same time using USB 1808-x Link to comment Share on other sites More sharing options...
0 DAQman Posted August 16, 2023 Share Posted August 16, 2023 Analog Input is similar to Analog Output, only in reverse. Allocate two buffers, one for input and one for output. The input buffer is 18-bit data, so use WinBufAlloc32 and WinBufAlloc for the 16-bit analog output. Create an unsigned short array for the waveform, then transfer it into the buffer you allocated with WinBufAlloc using the WinArrayToBuff function. Use AInScan and AOutScan with the scan options CONTINUOUS + BACKGROUND. With these options, both subsystems will run in the background, and you can use the GetStatus function to determine what each is doing. An example of what I'm talking about can be found below. If you want both systems to start simultaneously, include the EXTTRIGGER scan option and apply an external TTL trigger to the trigger terminal. #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <conio.h> #include <math.h> #include "cbw.h" #define NUM 4096 #define HALF NUM/2 #define OPTIONS CONTINUOUS + BACKGROUND #define BOARD 0 #define FIRST 0 #define LAST 0 #define CHANCOUNT 1 #define RESOLUTION 65536 bool inLower = TRUE; bool outLower = TRUE; int BoardNum = 0; //InstaCal's assigned board number int ULStat = 0; int LowChan = 0; int HighChan = 1; long iRate = 5000; long oRate = 5000; long Count = NUM; HGLOBAL MemHandleIn = 0; HGLOBAL MemHandleOut = 0; unsigned short pOut[NUM]; int ReadInput(); int WriteOutput(); void DisplayData(unsigned long datArray[], int rows); void main(void) { float RevLevel = (float)CURRENTREVNUM; double angle = 6.28318 / Count; double value; ULStat = cbDeclareRevision(&RevLevel); ULStat = cbErrHandling(PRINTALL, DONTSTOP); //Allocate internal buffers MemHandleIn = cbWinBufAlloc32(Count); MemHandleOut = cbWinBufAlloc(Count); //load up users output buffer with data for (int i = 0; i < Count; i++) { value = (sin(angle * i) + 1) * (RESOLUTION / 2); pOut[i] = (unsigned short)value; //printf("%d\n", pOut[i]); } cbAInputMode(BOARD, SINGLE_ENDED); //transfer users output buffer to an internal buffer cbWinArrayToBuf(pOut, MemHandleOut, 0, Count); //Start Analog Output ULStat = cbAOutScan(BOARD, FIRST, LAST, Count, &oRate, BIP10VOLTS, MemHandleOut, OPTIONS); //Start Analog Input ULStat = cbAInScan(BOARD, FIRST, LAST, Count, &iRate, BIP10VOLTS, MemHandleIn, OPTIONS); //loop reading and writing do { WriteOutput(); ReadInput(); } while (!kbhit()); cbStopBackground(BOARD, AIFUNCTION); cbStopBackground(BOARD, AOFUNCTION); cbWinBufFree(MemHandleIn); cbWinBufFree(MemHandleOut); } int ReadInput() { short status; long CurCount, CurIndex; unsigned long data[HALF]; cbGetStatus(BOARD, &status, &CurCount, &CurIndex, AIFUNCTION); if (CurCount > 0) { if ((CurIndex > HALF) & inLower) //check for 50% more data { ULStat = cbWinBufToArray32(MemHandleIn, data, 0, HALF); DisplayData(data, HALF / CHANCOUNT); inLower = FALSE; } else if ((CurIndex < HALF) & !inLower) { ULStat = cbWinBufToArray32(MemHandleIn, data, HALF, HALF); DisplayData(data, HALF / CHANCOUNT); inLower = TRUE; } } return 0; } int WriteOutput() { short status; long CurCount, CurIndex; unsigned short data[HALF]; cbGetStatus(BOARD, &status, &CurCount, &CurIndex, AOFUNCTION); if ((CurIndex >= HALF) & outLower) //check for 50% more data { ULStat = cbWinArrayToBuf(pOut + 0, MemHandleOut, 0, HALF); outLower = FALSE; } else if ((CurIndex < HALF) & !outLower) { ULStat = cbWinArrayToBuf(pOut + HALF, MemHandleOut, HALF, HALF); outLower = TRUE; } return 0; } void DisplayData(unsigned long datArray[], int rows) { //Writes data to screen and to file int i = 0; for (int row = 0; row < rows; row++) { for (int c = 0; c < CHANCOUNT; c++) { printf("%d\t", datArray[i]); i++; } printf("\r\n"); } } Link to comment Share on other sites More sharing options...
0 Charlie2134 Posted August 16, 2023 Author Share Posted August 16, 2023 6 hours ago, JRys said: Analog Input is similar to Analog Output, only in reverse. Allocate two buffers, one for input and one for output. The input buffer is 18-bit data, so use WinBufAlloc32 and WinBufAlloc for the 16-bit analog output. Create an unsigned short array for the waveform, then transfer it into the buffer you allocated with WinBufAlloc using the WinArrayToBuff function. Use AInScan and AOutScan with the scan options CONTINUOUS + BACKGROUND. With these options, both subsystems will run in the background, and you can use the GetStatus function to determine what each is doing. An example of what I'm talking about can be found below. If you want both systems to start simultaneously, include the EXTTRIGGER scan option and apply an external TTL trigger to the trigger terminal. #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <conio.h> #include <math.h> #include "cbw.h" #define NUM 4096 #define HALF NUM/2 #define OPTIONS CONTINUOUS + BACKGROUND #define BOARD 0 #define FIRST 0 #define LAST 0 #define CHANCOUNT 1 #define RESOLUTION 65536 bool inLower = TRUE; bool outLower = TRUE; int BoardNum = 0; //InstaCal's assigned board number int ULStat = 0; int LowChan = 0; int HighChan = 1; long iRate = 5000; long oRate = 5000; long Count = NUM; HGLOBAL MemHandleIn = 0; HGLOBAL MemHandleOut = 0; unsigned short pOut[NUM]; int ReadInput(); int WriteOutput(); void DisplayData(unsigned long datArray[], int rows); void main(void) { float RevLevel = (float)CURRENTREVNUM; double angle = 6.28318 / Count; double value; ULStat = cbDeclareRevision(&RevLevel); ULStat = cbErrHandling(PRINTALL, DONTSTOP); //Allocate internal buffers MemHandleIn = cbWinBufAlloc32(Count); MemHandleOut = cbWinBufAlloc(Count); //load up users output buffer with data for (int i = 0; i < Count; i++) { value = (sin(angle * i) + 1) * (RESOLUTION / 2); pOut[i] = (unsigned short)value; //printf("%d\n", pOut[i]); } cbAInputMode(BOARD, SINGLE_ENDED); //transfer users output buffer to an internal buffer cbWinArrayToBuf(pOut, MemHandleOut, 0, Count); //Start Analog Output ULStat = cbAOutScan(BOARD, FIRST, LAST, Count, &oRate, BIP10VOLTS, MemHandleOut, OPTIONS); //Start Analog Input ULStat = cbAInScan(BOARD, FIRST, LAST, Count, &iRate, BIP10VOLTS, MemHandleIn, OPTIONS); //loop reading and writing do { WriteOutput(); ReadInput(); } while (!kbhit()); cbStopBackground(BOARD, AIFUNCTION); cbStopBackground(BOARD, AOFUNCTION); cbWinBufFree(MemHandleIn); cbWinBufFree(MemHandleOut); } int ReadInput() { short status; long CurCount, CurIndex; unsigned long data[HALF]; cbGetStatus(BOARD, &status, &CurCount, &CurIndex, AIFUNCTION); if (CurCount > 0) { if ((CurIndex > HALF) & inLower) //check for 50% more data { ULStat = cbWinBufToArray32(MemHandleIn, data, 0, HALF); DisplayData(data, HALF / CHANCOUNT); inLower = FALSE; } else if ((CurIndex < HALF) & !inLower) { ULStat = cbWinBufToArray32(MemHandleIn, data, HALF, HALF); DisplayData(data, HALF / CHANCOUNT); inLower = TRUE; } } return 0; } int WriteOutput() { short status; long CurCount, CurIndex; unsigned short data[HALF]; cbGetStatus(BOARD, &status, &CurCount, &CurIndex, AOFUNCTION); if ((CurIndex >= HALF) & outLower) //check for 50% more data { ULStat = cbWinArrayToBuf(pOut + 0, MemHandleOut, 0, HALF); outLower = FALSE; } else if ((CurIndex < HALF) & !outLower) { ULStat = cbWinArrayToBuf(pOut + HALF, MemHandleOut, HALF, HALF); outLower = TRUE; } return 0; } void DisplayData(unsigned long datArray[], int rows) { //Writes data to screen and to file int i = 0; for (int row = 0; row < rows; row++) { for (int c = 0; c < CHANCOUNT; c++) { printf("%d\t", datArray[i]); i++; } printf("\r\n"); } } Thank you! I'm using Python but I'll look into the code. Thank you! Link to comment Share on other sites More sharing options...
Question
Charlie2134
Hello, I don't know how to output and measure the analog input signals at the same time using USB 1808-x
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now