Пример #1
0
void resetU6(uint8 res){
/*
  Resets U3
*/
  uint8 resetIn[4], resetOut[4];
  long int ii=0, error=0;

  for (ii=0; ii<4; ii++){
    resetIn[ii]=0;
    resetOut[ii]=0;
  }
  resetIn[1] = 0x99;
  resetIn[2] = res;
  resetIn[3] = 0x00;
  resetIn[0] = normalChecksum8(resetIn,4);

  if( (error = LJUSB_BulkWrite(hU6, U6_PIPE_EP1_OUT, resetIn, 4)) < 4){
    LJUSB_BulkRead(hU6, U6_PIPE_EP2_IN, resetOut, 4); 
    printf("U6 Reset error: %s\n", errormsg[(int)resetOut[3]]);
    closeUSBConnection(hU6);
    return;
  }
  printf ("....U6 device reset \n");
  return;
}
Пример #2
0
//Sends a StreamStop low-level command to stop streaming.
int StreamStop(HANDLE hDevice)
{
    uint8 sendBuff[2], recBuff[4];
    int sendChars, recChars;

    sendBuff[0] = (uint8)(0xB0);  //Checksum8
    sendBuff[1] = (uint8)(0xB0);  //Command byte

    //Sending command to U6
    sendChars = LJUSB_Write(hDevice, sendBuff, 2);
    if( sendChars < 2 )
    {
        if( sendChars == 0 )
            printf("Error : write failed (StreamStop).\n");
        else
            printf("Error : did not write all of the buffer (StreamStop).\n");
        return -1;
    }

    //Reading response from U6
    recChars = LJUSB_Read(hDevice, recBuff, 4);
    if( recChars < 4 )
    {
        if( recChars == 0 )
            printf("Error : read failed (StreamStop).\n");
        else
            printf("Error : did not read all of the buffer (StreamStop).\n");
        return -1;
    }

    if( normalChecksum8(recBuff, 4) != recBuff[0] )
    {
        printf("Error : read buffer has bad checksum8 (StreamStop).\n");
        return -1;
    }

    if( recBuff[1] != (uint8)(0xB1) || recBuff[3] != (uint8)(0x00) )
    {
        printf("Error : read buffer has wrong command bytes (StreamStop).\n");
        return -1;
    }

    if( recBuff[2] != 0 )
    {
        printf("Errorcode # %d from StreamStop read.\n", (unsigned int)recBuff[2]);
        return -1;
    }

    /*
    //Reading left over data in stream endpoint.  Only needs to be done with firmwares
    //less than 0.94.
    uint8 recBuffS[64];
    int recCharsS = 64;
    printf("Reading left over data from stream endpoint.\n");
    while( recCharsS > 0 )
        recCharsS = LJUSB_Stream(hDevice, recBuffS, 64);
    */

    return 0;
}
Пример #3
0
//Sends a StreamStart low-level command to start streaming.
int StreamStart(HANDLE hDevice)
{
    uint8 sendBuff[2], recBuff[4];
    int sendChars, recChars;

    sendBuff[0] = (uint8)(0xA8);  //Checksum8
    sendBuff[1] = (uint8)(0xA8);  //Command byte

    //Sending command to U6
    sendChars = LJUSB_Write(hDevice, sendBuff, 2);
    if( sendChars < 2 )
    {
        if( sendChars == 0 )
            printf("Error : write failed.\n");
        else
            printf("Error : did not write all of the buffer.\n");
        return -1;
    }

    //Reading response from U6
    recChars = LJUSB_Read(hDevice, recBuff, 4);
    if( recChars < 4 )
    {
        if( recChars == 0 )
            printf("Error : read failed.\n");
        else
            printf("Error : did not read all of the buffer.\n");
        return -1;
    }

    if( normalChecksum8(recBuff, 4) != recBuff[0] )
    {
        printf("Error : read buffer has bad checksum8 (StreamStart).\n");
        return -1;
    }

    if( recBuff[1] != (uint8)(0xA9) || recBuff[3] != (uint8)(0x00) )
    {
        printf("Error : read buffer has wrong command bytes \n");
        return -1;
    }

    if( recBuff[2] != 0 )
    {
        printf("Errorcode # %d from StreamStart read.\n", (unsigned int)recBuff[2]);
        return -1;
    }

    return 0;
}
Пример #4
0
void normalChecksum(uint8 *b, int n)
{
    b[0] = normalChecksum8(b,n);
}
Пример #5
0
void normalChecksum(std::array<unsigned char, MAXIMUM_BUFFER>* bytes, int count)
{
	(*bytes)[0] = normalChecksum8(*bytes, count);
}
Пример #6
0
unsigned char extendedChecksum8(const std::array<unsigned char, MAXIMUM_BUFFER>& bytes)
{
	return normalChecksum8(bytes, 6);
}
Пример #7
0
long ehSingleIO(HANDLE hDevice, uint8 inIOType, uint8 inChannel, uint8 inDirBipGainDACL, uint8 inStateResDACH, uint8 inSettlingTime, uint8 *outIOType, uint8 *outChannel, uint8 *outDirAINL, uint8 *outStateAINM, uint8 *outAINH)
{
  uint8 sendBuff[8], recBuff[8];
  int sendChars, recChars;

  sendBuff[1] = (uint8)(0xA3);    //command byte
  sendBuff[2] = inIOType;         //IOType
  sendBuff[3] = inChannel;        //Channel
  sendBuff[4] = inDirBipGainDACL; //Dir/BipGain/DACL
  sendBuff[5] = inStateResDACH;   //State/Resolution/DACH
  sendBuff[6] = inSettlingTime;  //Settling time
  sendBuff[7] = 0;                //Reserved
  sendBuff[0] = normalChecksum8(sendBuff, 8);

  //Sending command to UE9
  sendChars = LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, sendBuff, 8);
  if(sendChars < 8)
  {
    if(sendChars == 0)
      printf("SingleIO error : write failed\n");
    else
      printf("SingleIO error : did not write all of the buffer\n");
    return -1;
  }

  //Reading response from UE9
  recChars = LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, recBuff, 8);
  if(recChars < 8)
  {
    if(recChars == 0)
      printf("SingleIO error : read failed\n");
    else
      printf("SingleIO error : did not read all of the buffer\n");
      return -1;
  }

  if((uint8)(normalChecksum8(recBuff, 8)) != recBuff[0])
  {
    printf("SingleIO error : read buffer has bad checksum\n");
    return -1;
  }

  if(recBuff[1] != (uint8)(0xA3))
  {
    printf("SingleIO error : read buffer has wrong command byte\n");
    return -1;
  }

  if(outIOType != NULL)
    *outIOType = recBuff[2];
  if(outChannel != NULL)
    *outChannel = recBuff[3];
  if(outDirAINL != NULL)
    *outDirAINL = recBuff[4];
  if(outStateAINM != NULL)
    *outStateAINM = recBuff[5];
  if(outAINH != NULL)
    *outAINH = recBuff[6];

  return 0;
}
Пример #8
0
int readIntTemp(int socketFD, ue9CalibrationInfo *caliInfo, 
		double *dblIntTemp)
{
  uint8 sendBuff[8], recBuff[8];
  int sendChars, recChars;
  //  double voltage;
  double temperature; //in Kelvins
  uint16 bytesTemperature;
  uint8 ainResolution;

  ainResolution = 12;

  /* read temperature from internal temperature sensor */
  sendBuff[1] = (uint8)(0xA3);  //command byte
  sendBuff[2] = (uint8)(0x04);  //IOType = 4 (analog in)
  sendBuff[3] = (uint8)(0x85);  //Channel = 133 (tempSensor)
  sendBuff[4] = (uint8)(0x00);  //Gain = 1 (Bip does not apply)  
  sendBuff[5] = (uint8)(0x0C);  //Resolution = 12
  sendBuff[6] = (uint8)(0x00);  //SettlingTime = 0
  sendBuff[7] = (uint8)(0x00);  //Reserved
  sendBuff[0] = normalChecksum8(sendBuff, 8);

  //Sending command to UE9
  sendChars = send(socketFD, sendBuff, 8, 0);
  if(sendChars < 8)
  {
    if(sendChars == -1)
      goto sendError0;
    else  
      goto sendError1;
  }

  //Receiving response from UE9
  recChars = recv(socketFD, recBuff, 8, 0);
  if(recChars < 8)
  {
    if(recChars == -1)
      goto recvError0;
    else  
      goto recvError1;
  }

  if((uint8)(normalChecksum8(recBuff, 8)) != recBuff[0])
    goto chksumError;

  if(recBuff[1] != (uint8)(0xA3))
    goto commandByteError;

  if(recBuff[2] != (uint8)(0x04))
    goto IOTypeError;

  if(recBuff[3] != (uint8)(0x85))
    goto channelError;

  bytesTemperature = recBuff[5] + recBuff[6] * 256;

  //assuming high power level
  if(binaryToCalibratedAnalogTemperature(caliInfo, 0, bytesTemperature, 
					 &temperature) < 0)
    return -1;

  *dblIntTemp = temperature;
  
  return 0;

//error printouts
sendError0:
  printf("Error : send failed\n");
  return -1;
sendError1:
  printf("Error : did not send all of the buffer\n");
  return -1;
recvError0:
  printf("Error : recv failed\n");
  return -1;
recvError1:  
  printf("Error : recv did not receive all of the buffer\n");
  return -1;
chksumError:
  printf("Error : received buffer has bad checksum\n");
  return -1;
commandByteError:
  printf("Error : received buffer has wrong command byte\n");
  return -1;
IOTypeError:  
  printf("Error : received buffer has wrong IOType\n");
  return -1;
channelError:  
  printf("Error : received buffer has wrong channel\n");
  return -1;

}