#include <readline/history.h>
-unsigned char seq=0;
-
//This routine locates a scope by VID/PID and returns an opened handle to it.
usb_dev_handle *find_scope() {
struct usb_bus *bus;
//Send a scpi-command to the scope. The response goes into the buffer
//called resp, with a size of resplen. If resp==NULL, no response
//is requested.
-int sendscpi(usb_dev_handle *dev, unsigned char* cmd,
+int sendscpi(usb_dev_handle *dev, char* cmd,
unsigned char *resp, int resplen) {
- char *buff;
+ unsigned char *buff;
int len,r,i;
+ int cmdlen = strlen(cmd);
+ static unsigned char seq=0;
+
+
buff=malloc(0x40);
seq++;
buff[0]=1; //func
buff[1]=seq; buff[2]=~seq; //nseq
buff[3]=0;
- int2chars(buff+4,strlen(cmd));
+ int2chars(buff+4, cmdlen);
buff[8]=1;
buff[9]=0x37;
buff[10]=0x39;
buff[11]=0x39;
- // fprintf(stderr,"Writing header len=%d\n", strlen (cmd));
+ // fprintf(stderr,"Writing header len=%d\n", cmdlen);
// printb(buff,12);
- r=usb_bulk_write(dev,1,buff,12,1000);
+ r=usb_bulk_write(dev, 1, (char*)buff, 12, 1000);
// fprintf(stderr,"%i bytes written. Writing cmd\n",r);
-// printb(cmd,strlen(cmd));
- r=usb_bulk_write(dev,1,cmd,strlen(cmd),1000);
+// printb(cmd, cmdlen);
+ r=usb_bulk_write(dev, 1, cmd, cmdlen, 1000);
// fprintf(stderr,"%i bytes written.\n",r);
if (resp != NULL && resplen != 0) {
//send read command
buff[11]=0;
// fprintf(stderr,"Writing resp req header\n");
// printb(buff,12);
- r=usb_bulk_write(dev,1,buff,12,1000);
+ r=usb_bulk_write(dev, 1, (char*)buff, 12, 1000);
// fprintf(stderr,"%i bytes written. Reading response hdr\n",r);
- r=usb_bulk_read(dev,2,buff,0x40,1000);
+ r=usb_bulk_read(dev, 2, (char*)buff, 0x40, 1000);
// printb(buff,r);
len=chars2int(buff+4);
// fprintf(stderr,"%i bytes read. Resplen=%i\n",r,len);
if (len > 0x40-12) {
// fprintf(stderr," Reading response:\n");
if (resplen<len) len=resplen;
- r=usb_bulk_read(dev,2,resp+(0x40-12),len-(0x40-12),1000);
+ r=usb_bulk_read(dev, 2, (char*)resp+(0x40-12), len-(0x40-12),1000);
// fprintf(stderr,"%i bytes read, wanted %i.\n", r, len-(0x40-12));
return r+(0x40-12);
}
//Initialize the scope.
void initscope(usb_dev_handle *dev) {
int r;
- char buff[10];
+ unsigned char buff[10];
usb_claim_interface(dev,0);
//The following code isn't really necessary, the program works
//OK without it too.
- r=usb_control_msg(dev, 0xC8, 9, 0, 0, buff, 4, 1000);
+ r=usb_control_msg(dev, 0xC8, 9, 0, 0, (char*)buff, 4, 1000);
if (r < 0) {
fprintf (stderr, "Error %d sending init message: %s\n",
r, strerror (-r));
l = sendscpi(sc, var, buf, 1024);
if (l > 0) {
- sscanf (buf, "%lf", &temp);
+ sscanf ((char*)buf, "%lf", &temp);
return temp;
}
return ERROR;
{
FILE *fp;
int i, j, l, bp;
- unsigned char buf[1024], ch1[1024];
+ char buf[1024];
+ unsigned char ch1[1024];
unsigned char data[512*1024];
double sampfreq;
int main(int argc, char **argv)
{
struct usb_dev_handle *sc;
- char *scpi, *buff;
+ char *scpi;
+ unsigned char *buff;
int l;
//Init libusb
usb_init();