Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wjasper committed Oct 5, 2018
1 parent e4861cd commit 9679f12
Show file tree
Hide file tree
Showing 13 changed files with 940 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Ethernet/c/ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ int flushInput(int sock)
int sendMessage(int sock, void *message, int length, int flags)
{
flushInput(sock);
return send(sock, message, length, flags);
return send(sock, message, length, flags);
}

int receiveMessage(int sock, void *message, int maxLength, unsigned long timeout)
Expand Down
23 changes: 21 additions & 2 deletions Ethernet/python/mccPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@ def calcChecksum(self, buf, length):
checksum += buf[i]
return (checksum & 0xff)

def flushInput(self):
# Flush input buffers.
numTotal = 0
while True:
try:
cbuf = self.sock.recv(512, self.sock.MSG_DONTWAIT)
numTotal += len(cbuf)
except:
break
if numTotal > 0:
print('flushInput flushed', numTotal, 'bytes')
return numTotal

def sendMessage(self, messge, flush=True):
if (flush):
self.flushInput()
self.sock.send(message)


############### end class defition ##########################

def mccDiscover(productID=None):
Expand Down Expand Up @@ -187,13 +206,13 @@ def mccDiscover(productID=None):
return devices


# Structures for Temperature */
# Structures for Temperature
##################################################
# NIST Thermocouple coefficients
#
# The following types are supported:
#
# J, K, R, S, T, N, E, B
# J, K, T, E, R, S, B, N
#
# Define the types of Thermocouples supported */

Expand Down
3 changes: 3 additions & 0 deletions PCI/pcim-das1602-16/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ default:
test-pcim-das1602-16: test-pcim-das1602-16.c
$(CC) -Wall -g -o $@ $@.c -lm

main: main.cpp
g++ -Wall -g -o $@ $@.cpp -lm

clean:
rm -f *.o *~ \#* .pcim-das1602-16.*.cmd pcim-das1602-16.mod.c .a2dc.*.cmd $(TARGETS)
rm -rf .tmp_versions
Expand Down
2 changes: 1 addition & 1 deletion PCI/pcim-das1602-16/a2dc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef A2DC_H
#define A2DC_H

//#define DEBUG 1
#define DEBUG 1
#define ADAPTER_ID "PCIM-DAS1602-16.v1.6"

/*****************************
Expand Down
16 changes: 11 additions & 5 deletions PCI/pcim-das1602-16/a2dc_4_10_0.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ static int das1602_init_one(struct pci_dev *pdev, const struct pci_device_id *en
device_create(das1602_class, NULL, MKDEV(MajorNumber, minor), NULL, name);
}

printk("das1602_init_one: created devices in /dev.\n");

BoardData[NumBoards].nonBlockFile = NULL;

BoardData[NumBoards].nSpare1 = (GATE_EN);
Expand All @@ -380,15 +382,19 @@ static int das1602_init_one(struct pci_dev *pdev, const struct pci_device_id *en
spin_lock_init(&das1602_lock);

BoardData[NumBoards].buf_phy_size = ALIGN_ADDRESS(ADC_BUFF_PHY_SIZE, PAGE_SIZE);
BoardData[NumBoards].buf_virt_addr = (u16 *) pci_alloc_consistent( 0,
printk("das1602_init_one: getting physical buffer size. = %#x\n", BoardData[NumBoards].buf_phy_size);

BoardData[NumBoards].buf_virt_addr = (u16 *) pci_alloc_consistent( pdev,
BoardData[NumBoards].buf_phy_size,
&BoardData[NumBoards].buf_bus_addr);
printk("das1602_init_one: getting virtual address = %p\n", BoardData[NumBoards].buf_virt_addr);
if (BoardData[NumBoards].buf_virt_addr == 0x0) return -ENOMEM;

/* set PG_reserved flag on DMA memory pages.
This protects them from the VM system after they're mmap()'d
*/


printk("das1602_init_one: reserving DMA memory pages.\n");
page = virt_to_page(BoardData[NumBoards].buf_virt_addr);
for (i = 0; i < BoardData[NumBoards].buf_phy_size/PAGE_SIZE; i++) {
SetPageReserved(&page[i]);
Expand All @@ -412,7 +418,7 @@ static int das1602_init_one(struct pci_dev *pdev, const struct pci_device_id *en
BoardData[NumBoards].ADC_acqtype = ADC_ACQ_NORMAL;
#ifdef DEBUG
printk("das1602_init-one: Board %d: ringbuf_vaddr = %p ringbuf_size: %d\n",
NumBoards, BoardData[Numboards].ringbuf_vaddr, BoardData[NumBoards].rb_size);
NumBoards, BoardData[NumBoards].ringbuf_vaddr, BoardData[NumBoards].rb_size);
#endif

printk("%s: BADR0=%#x BADR1=%#x BADR2=%#x BADR3=%#x BADR4=%#x\n",
Expand Down Expand Up @@ -477,7 +483,7 @@ static void das1602_remove_one(struct pci_dev *pdev)
ClearPageReserved(&page[i]);
}

pci_free_consistent(0,
pci_free_consistent(pdev,
BoardData[NumBoards].buf_phy_size,
BoardData[NumBoards].buf_virt_addr,
BoardData[NumBoards].buf_bus_addr);
Expand Down Expand Up @@ -1253,7 +1259,7 @@ static int das1602_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
vmf->page = virt_to_page(v_addr);

#ifdef DEBUG
printk ("pcim-das1602_fault mapped address %p to %p\n", vmf->address, v_addr);
printk ("pcim-das1602_fault mapped address %ld to %p\n", vmf->address, v_addr);
#endif
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion USB/mcc-libusb/test-usb-temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int main(int argc, char **argv)
usbSetItem_USBTEMP(hid, ch/2, SENSOR_TYPE, SEMICONDUCTOR);
printf(" 1. Single ended.\n");
printf(" 2. Differential.\n");
printf("Enter connector type [1-4]: \n");
printf("Enter connection type [1-2]: \n");
scanf("%d", &i);
switch (i) {
case 1: usbSetItem_USBTEMP(hid, ch/2, CONNECTION_TYPE, SINGLE_ENDED);break;
Expand Down
2 changes: 1 addition & 1 deletion USB/mcc-libusb/test-usb1608FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ int main (int argc, char **argv)
printf("Port = %#hx\n", wvalue);
break;
case 'C':
printf("USB-1608FS Continuous sampling. Hit 's' to stop\n");
printf("USB-1608FS Continuous sampling. Hit 's' to stop\n");
printf("Enter desired frequency [Hz]: ");
scanf("%f", &freq);
gain = BP_10_00V;
Expand Down
2 changes: 1 addition & 1 deletion USB/mcc-libusb/usb-1208FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ int usbAInScan_USB1208FS(libusb_device_handle *udev, uint8_t lowchannel, uint8_t
i += 31;
break;
}
pipe = (pipe)%3 + 1; //pipe should take the values 1, 2 or 3
pipe = pipe%3 + 1; //pipe should take the values 1, 2 or 3
}

usbAInStop_USB1208FS(udev);
Expand Down
4 changes: 2 additions & 2 deletions USB/mcc-libusb/usb-temp.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void usbTin_USBTEMP(hid_device *hid, uint8_t channel, uint8_t units, float *valu
{
/*
This command reads the value from the specified input channel. The return
value is a 32-bit floating point value in the units configured fro the
value is a 32-bit floating point value in the units configured for the
channel. CJC readings will always be in Celsius.
*/

Expand Down Expand Up @@ -498,7 +498,7 @@ void usbWriteCode_USBTEMP(hid_device *hid, uint32_t address, uint8_t count, uint
/*
This command writes to the program memory in the device. This command is not accepted
unless the device is in update mode. This command will normally be used when downloading
a nex hex file, so it supports memory ranges that may be found in the hex file. The
a new hex file, so it supports memory ranges that may be found in the hex file. The
microcontroller that is being written to is selected with the "Prepare Download" command.
The address ranges are:
Expand Down
226 changes: 226 additions & 0 deletions USB/python/test-usb-temp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
#! /usr/bin/python3
#
# Copyright (c) 2018 Warren J. Jasper <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


from usb_temp import *
import time
import sys
import fcntl
import os
import math

def toContinue():
answer = input('Continue [yY]? ')
if (answer == 'y' or answer == 'Y'):
return True
else:
return False

def celsius2fahr(celsius):
return (celsius*9.0/5.0 + 32.)

def fahr2celsius(fahr):
return (fahr - 32.)*5.0/9.0

def main():
dev = usb_temp() # USB-TEMP
dev.DConfig(dev.DIO_DIR_OUT)
dev.DOut(0x0)

while True:
print("\nTesting USB-TEMP")
print("----------------")
print("Hit 'b' to blink LED")
print("Hit 'c' to calibrate");
print("Hit 'd' to test digital I/O ")
print("Hit 'e' to exit")
print("Hit 'f' for burnout status");
print("Hit 'g' to get serial number")
print("Hit 'i' for information")
print("Hit 'R' to reset");
print("Hit 'r' to measure temperature (RTD)");
print("Hit 'p' read the CJC");
print("Hit 's' to get status");
print("Hit 'S' to measure temperature (Semiconductor)");
print("Hit 't' to measure temperature (Thermocouple)");
print("Hit 'T' to measure temperature (Thermistor)");
print("Hit 'x' to measure temperature (Thermocouple) multiple channels");
ch = input('\n')

if ch == 'b':
dev.Blink()
elif ch == 'e':
dev.h.close()
exit(0)
elif ch == 'f':
print('Burnout status =', hex(dev.BurnoutStatus(0xf)))
elif ch == 'd':
print('Testing Digital Bit I/O')
print('Connect pins DIO0 through DIO3 <==> DIO4 through DIO7')
dev.DConfigBit(0,dev.DIO_DIR_OUT)
dev.DConfigBit(1,dev.DIO_DIR_OUT)
dev.DConfigBit(2,dev.DIO_DIR_OUT)
dev.DConfigBit(3,dev.DIO_DIR_OUT)
dev.DConfigBit(4,dev.DIO_DIR_IN)
dev.DConfigBit(5,dev.DIO_DIR_IN)
dev.DConfigBit(6,dev.DIO_DIR_IN)
dev.DConfigBit(7,dev.DIO_DIR_IN)
while True:
value = int(input('Enter number [0-f]: '),16)
dev.DBitOut(0, value & 0x1)
dev.DBitOut(1, value & 0x2)
dev.DBitOut(2, value & 0x4)
dev.DBitOut(3, value & 0x8)
value = dev.DBitIn(4) | dev.DBitIn(5) << 1 | dev.DBitIn(6) << 2 | dev.DBitIn(7) << 3
print('The value you read is',hex(value))
if toContinue() != True:
break
elif ch == 's':
print('Status = ', hex(dev.Status()))
elif ch == 'i':
print("Manufacturer: %s" % dev.h.get_manufacturer_string())
print("Product: %s" % dev.h.get_product_string())
print("Serial No: %s" % dev.h.get_serial_number_string())
elif ch == 'p':
print('Reading CJC')
temperature = dev.AIn(dev.CJC0, 0)
print('CJC 0 =', format(temperature,'.2f'),'degrees Celsius or',format(celsius2fahr(temperature),'.2f'),'degrees Fahrenheit')
temperature = dev.AIn(dev.CJC1, 0)
print('CJC 1 =', format(temperature,'.2f'),'degrees Celsius or',format(celsius2fahr(temperature),'.2f'),'degrees Fahrenheit')
elif ch == 't':
chan = int(input('Select Channel [0-7]: '))
dev.SetItem(int(chan/2), dev.SENSOR_TYPE, dev.THERMOCOUPLE)
dev.SetItem(int(chan/2), dev.EXCITATION, dev.EXCITATION_OFF)
print('Conect thermocouple to channel',chan)
t_type = input('Select Thermocouple type [JKSRBETN]: ')
if t_type == 'J':
t_type = dev.TC_TYPE_J
print('Type J thermocouple selected.')
elif t_type == 'K':
t_type = dev.TC_TYPE_K
print('Type K thermocouple selected.')
if t_type == 'S':
t_type = dev.TC_TYPE_S
print('Type S thermocouple selected.')
if t_type == 'R':
t_type = dev.TC_TYPE_R
print('Type R thermocouple selected.')
if t_type == 'B':
t_type = dev.TC_TYPE_B
print('Type B thermocouple selected.')
if t_type == 'E':
t_type = dev.TC_TYPE_E
print('Type E thermocouple selected.')
if t_type == 'T':
t_type = dev.TC_TYPE_T
print('Type T thermocouple selected.')
if t_type == 'N':
t_type = dev.TC_TYPE_N
print('Type N thermocouple selected.')
dev.SetItem(int(chan/2), chan%2+dev.CH_0_TC, t_type)
dev.Calibrate()
for i in range(20):
temperature = dev.AIn(chan,0)
print('Channel: ',chan, format(temperature,'.2f'),'degrees Celsius or',\
format(celsius2fahr(temperature),'.2f'),'degrees Fahrenheit')
time.sleep(1)
elif ch == 'S':
print('Sampling Semiconductor TMP36')
chan = int(input('Enter channel number [0-7]: '))
dev.SetItem(int(chan/2), dev.SENSOR_TYPE, dev.SEMICONDUCTOR)
print('\t\t 1. Single ended')
print('\t\t 2. Differential.')
connection_type = int(input('Enter connection type [1-2]: '))
if connection_type == 1:
dev.SetItem(int(chan/2), dev.CONNECTION_TYPE, dev.SINGLE_ENDED)
else:
dev.SetItem(int(chan/2), dev.CONNECTION_TYPE, dev.DIFFERENTIAL)
offset = float(input('Enter Offset: '))
scale = float(input('Enter slope (scale): '))
dev.SetItem(int(chan/2), dev.EXCITATION, dev.EXCITATION_OFF)
dev.SetItem(int(chan/2), dev.CH_0_GAIN + chan%2, 0x1) # Set for Semiconductor
dev.SetItem(int(chan/2), dev.CH_0_COEF_0 + chan%2, offset) # Offset
value = dev.GetItem(int(chan/2), dev.CH_0_COEF_0 + chan%2)
print('Offset =', format(value,'.4f'))
dev.SetItem(int(chan/2), dev.CH_0_COEF_1 + chan%2, scale) # Scale factor
value = dev.GetItem(int(chan/2), dev.CH_0_COEF_1 + chan%2)
print('Scale Factor =', format(value,'.4f'))
flag = fcntl.fcntl(sys.stdin, fcntl.F_GETFL)
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, flag|os.O_NONBLOCK)
while True:
temperature = dev.AIn(chan, 0)
print('Channel',chan,format(temperature,'.2f'),'degrees Celsius or',\
format(celsius2fahr(temperature),'.2f'),'degrees Fahrenheit.')
time.sleep(1)
c = sys.stdin.readlines()
if (len(c) != 0):
break
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, flag)
elif ch == 'r':
print('Sampling RTD')
chan = int(input('Enter channel number [0-7]: '))
dev.SetItem(int(chan/2), dev.SENSOR_TYPE, dev.RTD)
print('\t\t 1. 2 - wire with 1 sensor.')
print('\t\t 2. 2 - wire with 2 sensor.')
print('\t\t 2. 3 - wire.')
print('\t\t 4. 4 - wire.')
rtd_type = int(input('Enter RTD type [1-4]: '))
if rtd_type == 1:
dev.SetItem(int(chan/2), dev.CONNECTION_TYPE, dev.TWO_WIRE_ONE_SENSOR)
elif rtd_type == 2:
dev.SetItem(int(chan/2), dev.CONNECTION_TYPE, dev.TWO_WIRE_TWO_SENSOR)
elif rtd_type == 3:
dev.SetItem(int(chan/2), dev.CONNECTION_TYPE, dev.THREE_WIRE)
elif rtd_type == 4:
dev.SetItem(int(chan/2), dev.CONNECTION_TYPE, dev.FOUR_WIRE)
else:
print('Unknown value.')
break
R0 = 100.
A = 0.003908
B = -5.8019e-7
C = -4.2735e-12
dev.SetItem(int(chan/2), dev.EXCITATION, dev.MU_A_210)
dev.SetItem(int(chan/2), dev.CH_0_GAIN + chan%2, 0x2) # Set 0 - 0.5V for RTD
dev.SetItem(int(chan/2), dev.CH_0_COEF_0 + chan%2, R0) # R0 value
value = dev.GetItem(int(chan/2), dev.CH_0_COEF_0 + chan%2)
print('R0 =',format(value,'.4f'))
dev.SetItem(int(chan/2), dev.CH_0_COEF_1 + chan%2, A) # Callendar-Van Dusen Coefficient A
value = dev.GetItem(int(chan/2), dev.CH_0_COEF_1 + chan%2)
print('A =',format(value,'.4f'))
dev.SetItem(int(chan/2), dev.CH_0_COEF_2 + chan%2, B) # Callendar-Van Dusen Coefficient B
value = dev.GetItem(int(chan/2), dev.CH_0_COEF_2 + chan%2)
print('B =',format(value,'.4e'))
dev.SetItem(int(chan/2), dev.CH_0_COEF_3 + chan%2, C) # Callendar-Van Dusen Coefficient C
value = dev.GetItem(int(chan/2), dev.CH_0_COEF_3 + chan%2)
print('C =',format(value,'.4e'))
flag = fcntl.fcntl(sys.stdin, fcntl.F_GETFL)
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, flag|os.O_NONBLOCK)
while True:
temperature = dev.AIn(chan, 0)
print('Channel',chan,format(temperature,'.2f'),'degrees Celsius or',\
format(celsius2fahr(temperature),'.2f'),'degrees Fahrenheit.')
time.sleep(1)
c = sys.stdin.readlines()
if (len(c) != 0):
break
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, flag)



if __name__ == "__main__":
main()
Loading

0 comments on commit 9679f12

Please sign in to comment.