BeeHay Posted January 26, 2009 Share Posted January 26, 2009 Having a tough time enabling my analog output (there are 3 outs) on my lawson labs board... I did mess with the extern stuff when I initally started DF, but that was sometime ago. Here is some documentation from their site. BOOLEAN SendAnalogOut(void) { // Supported by Model 302 only BYTE bDAC = 1; DOUBLE dblVoltage = 2.5; bCurListIndex = 0; if(!pSP_SendDAC(pausDevList[bCurListIndex], dlbVoltage, bDAC, bReserved)) { /* do critical error handling here */ } // Update controls to reflect new DAC settings } Now I have added this to my device config - extern("ll_usb2k.dll","ubyte EX_SendDAC(uword, double[1], ubyte)","SendDAC","stdcall","DevID, Output, Channel") global SendDAC=0 ....and have made a button with this quick sequence - SendDAC(@DevID[0], @double[1], @ubyte, 0, 2.5, 1) Just trying to get one of the 3 output channels to display 2.5. Thanks in advance!! Link to comment Share on other sites More sharing options...
AzeoTech Posted January 27, 2009 Share Posted January 27, 2009 Alas, the snippet you sent from their manual shows a sample of how to call their function from C. I need to see the exact prototype of the EX_SendDAC() function, preferably from the .h header file they provide. Link to comment Share on other sites More sharing options...
BeeHay Posted January 27, 2009 Author Share Posted January 27, 2009 Does this help? (you dont have to post this if not needed) BOOLEAN SP_SendDAC(USHORT usDevID, DOUBLE dblVoltage, BYTE bDAC, BYTE* pbReserved); Arguments usDevID: 16-bit data variable representing the device that you wish to send analog data to. dblVoltage: Voltage to send to Model-302 bDAC: 8-bit data variable that represents the channel to send the analog voltage to pbReserved: Pointer to an 8-bit data variable. This is currently reserved for future use. Return type: 8-bit. 1 (true) = success, 0 (false) = failed Link to comment Share on other sites More sharing options...
AzeoTech Posted January 28, 2009 Share Posted January 28, 2009 Yes. Your extern was wrong. You want (I believe): extern("ll_usb2k.dll","ubyte SP_SendDAC(uword, double, ubyte, ubyte[1])","SendDAC","stdcall","DevID, Output, Channel") That should fix it. You have to get the prototype EXACTLY right or you'll likely crash DAQFactory because the stack will get messed up. Your extern only had three parameters, and had the double as a pointer by doing [1]. Only the 4th parameter is a pointer. Link to comment Share on other sites More sharing options...
BeeHay Posted January 28, 2009 Author Share Posted January 28, 2009 Awesome as always, thanks! Link to comment Share on other sites More sharing options...
BeeHay Posted November 10, 2009 Author Share Posted November 10, 2009 Hmm, thought I had this working, but must have since lost that .ctl file... Would this be the correct way to send out to my analog out? SendDac(DevID[0], 1, 0)? I'm getting "Invalid number of parameters." Also, would like to get the Digital Out to work. Would this be the correct way to add it to my device config? - extern("llusb_2k.dll" "ubyte EX_SendDigout (uword, ubyte)","SendDigOut","stdcall","DevID", Digital Chn Out") Anything helps! Thanks! Link to comment Share on other sites More sharing options...
AzeoTech Posted November 12, 2009 Share Posted November 12, 2009 No, and no I'm afraid. For SendDac, it requires four parameters. Look at the actual prototype. The fourth parameter is reserved, but still has to be passed. Just make a private called junk and pass a pointer to it (@junk) As for the second one, I don't have the prototype in front of me to compare, but you have some basic errors: 1) you can't have a space after the function name and before the ( in the prototype. 2) you have an extra quote in the 5th parameter of extern. It says "DevID", and should say "DevID, Link to comment Share on other sites More sharing options...
BeeHay Posted November 13, 2009 Author Share Posted November 13, 2009 I was wondering what to do with the 4 parameter. Ahh, now I see why the close ) wasn't turning blue. :bonk: The prototype for the second is this - BOOLEAN SP_SendDigOut(USHORT usDevID, BYTE bDigOut, BYTE* pbReserved); This call is used to send a digital output value to the device. It can be used anytime once the device has been initialized. Valid digital output values are 0-255. Arguments usDevID: 16-bit data variable representing the device that you wish to send the digital output to. bDigOut: 8-bit data variable that represents the desired digital output. pbReserved: Pointer to an 8-bit data variable. This is currently reserved for future use. Return type: 8-bit. 1 (true) = success, 0 (false) = failed I need to add the resereved parameter, correct? When I call this, will this just toggle the digital channel I call to "on/off"? It says valid ranges are 0-255, how would I tell it say, "200"? Thanks again! Link to comment Share on other sites More sharing options...
AzeoTech Posted November 13, 2009 Share Posted November 13, 2009 C doesn't really have optional parameters (unlike C++), so if its in the prototype, you have to use it, even if its just a junk or reserved parameter. Typically you want to pass 0 to reserved parameters, but that's up to the manufacturer. So your prototype is (uword, ubyte, ubyte[1]). I don't know the details of this function, but it either sets a single digital out on/off or a whole bank of 8 by looking at the 8 bits. Link to comment Share on other sites More sharing options...
BeeHay Posted November 13, 2009 Author Share Posted November 13, 2009 Thanks again for everything. Haven't tested it yet, will post back with results. Link to comment Share on other sites More sharing options...
BeeHay Posted November 20, 2009 Author Share Posted November 20, 2009 SendDac(DevID[0], 1.9, 0, @junk) and SendDigOut(DevID[0], 250, @junk) work great. It looks like I need to use a different extern to specify my digital channel out. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.