Phidget API 22 : libusb deadlock - c

I currently have a thread of the Phidget API which deadlocks; here is a stack trace of my main thread:
1 __lll_lock_wait 0x7ffff5b3173c
2 __lll_lock_elision 0x7ffff5b343c7
3 mos_mutex_lock mos_lock-pthread.c 288 0x7fffd64b50ee
4 StartCentralThread phidget22.c 205 0x7fffd64d45dd
5 registerChannel phidget.c 1348 0x7fffd64d2432
6 Phidget_open_internal phidget.c 1416 0x7fffd64d2432
7 list_phidgets phidgets_parameter.hpp 1076 0x7fffd6139f9b
/* list_phidgets is in my own code and calls Phidget_open(...) */
and an offending internal libphidget thread :
1 poll 0x7ffff12ba97b
2 ?? 0x7ffff54cb6ec
3 libusb_handle_events_timeout_completed 0x7ffff54cc76a
4 libusb_handle_events_completed 0x7ffff54cc8b0
5 ?? 0x7ffff54cd1d9
6 libusb_control_transfer 0x7ffff54cd539
7 libusb_get_string_descriptor_ascii 0x7ffff54ca47e
8 PhidgetUSBGetString usblinux.c 253 0x7fffd64d5319
9 scanVintDevices vint.c 218 0x7fffd64e5a2e
10 PhidgetManager_poll manager.c 380 0x7fffd64bc87c
11 CentralThreadFunction phidget22.c 371 0x7fffd64d4415
12 start_thread 0x7ffff5b2808c
13 clone 0x7ffff12c4e7f
Phidget_open called from my main thread, opens a mutex also opened in CentralThreadFunction, and libusb_get_string_descriptor_ascii does not seem to return which deadlocks my whole app. What can I do ?

Related

Issues Regarding SAS

I was working on a homework problem regarding using arrays and looping to create a new variable to identify the date of when the maximum blood lead value was obtained but got stuck. For context, here is the homework problem:
In 1990 a study was done on the blood lead levels of children in Boston. The following variables for twenty-five children from the study have been entered on multiple lines per subject in the file lead_sum2018.txt in a list format:
Line 1
ID Number (numeric, values 1-25)
Date of Birth (mmddyy8. format)
Day of Blood Sample 1 (numeric, initial possible range: -9 to 31)
Month of Blood Sample 1 (numeric, initial possible range: -9 to 12)
Line 2
ID Number (numeric, values 1-25)
Day of Blood Sample 2 (numeric, initial possible range: -9 to 31)
Month of Blood Sample 2 (numeric, initial possible range: -9 to 12)
Line 3
ID Number (numeric, values 1-25)
Day of Blood Sample 3 (numeric, initial possible range: -9 to 31)
Month of Blood Sample 3 (numeric, initial possible range: -9 to 12)
Line 4
ID Number (numeric, values 1-25)
Blood Lead Level Sample 1 (numeric, possible range: 0.01 – 20.00)
Blood Lead Level Sample 2 (numeric, possible range: 0.01 – 20.00)
Blood Lead Level Sample 3 (numeric, possible range: 0.01 – 20.00)
Sex (character, ‘M’ or ‘F’)
All blood samples were drawn in 1990. However, during data entry the order of blood samples was scrambled so that the first blood sample in the data file (blood sample 1) may not correspond to the first blood sample taken on a subject, it could be the first, second or third. In addition, some of the months and days and days of blood sampling were not written on the forms. At data entry, missing month and missing day values were each coded as -9.
The team of investigators for this project has made the following decisions regarding the missing values. Any missing days are to set equal to 15, any missing months are to be set equal to 6. Any analyses that are done on this data set need to follow those decisions. Be sure to implement the SAS syntax as indicated for each question. For example, use SAS arrays and loops if the item states that these must be used.
Here is the data that the HW references (it is in list format and was contained in a separate file called lead_sum2018.txt):
1 04/30/78 6 10
1 -9 7
1 14 1
1 1.62 1.35 1.47 F
2 05/19/79 27 11
2 20 -9
2 5 6
2 1.71 1.31 1.76 F
3 01/03/80 11 7
3 6 6
3 27 2
3 3.24 3.4 3.83 M
4 08/01/80 5 12
4 28 -9
4 3 4
4 3.1 3.69 3.27 M
5 12/26/80 21 5
5 3 7
5 -9 12
5 4.35 4.79 5.14 M
6 06/20/81 7 10
6 11 3
6 22 1
6 1.24 1.16 0.71 F
7 06/22/81 19 6
7 3 12
7 29 8
7 3.1 3.21 3.58 F
8 05/24/82 26 7
8 31 1
8 9 10
8 2.99 2.37 2.4 M
9 10/11/82 2 7
9 25 5
9 28 3
9 2.4 1.96 2.71 F
10 . 10 8
10 30 12
10 28 2
10 2.72 2.87 1.97 F
11 11/16/83 19 4
11 15 11
11 7 -9
11 4.8 4.5 4.96 M
12 03/02/84 17 6
12 11 2
12 17 11
12 2.38 2.6 2.88 F
13 04/19/84 2 12
13 -9 6
13 1 7
13 1.99 1.20 1.21 M
14 02/07/85 4 5
14 17 5
14 21 11
14 1.61 1.93 2.32 F
15 07/06/85 5 2
15 16 1
15 14 6
15 3.93 4 4.08 M
16 09/10/85 12 10
16 11 -9
16 23 6
16 3.29 2.88 2.97 M
17 11/05/85 12 7
17 18 1
17 11 11
17 1.31 0.98 1.04 F
18 12/07/85 16 2
18 18 4
18 -9 6
18 2.56 2.78 2.88 M
19 03/02/86 19 4
19 11 3
19 19 2
19 0.79 0.68 0.72 M
20 08/19/86 21 5
20 15 12
20 -9 4
20 0.66 1.15 1.42 F
21 02/22/87 16 12
21 17 9
21 13 4
21 2.92 3.27 3.23 M
22 10/11/87 7 6
22 1 12
22 -9 3
22 1.43 1.42 1.78 F
23 05/12/88 12 2
23 21 4
23 17 12
23 0.55 0.89 1.38 M
24 08/07/88 17 6
24 27 11
24 6 2
24 0.31 0.42 0.15 F
25 01/12/89 4 7
25 15 -9
25 23 1
25 1.69 1.58 1.53 M
A) Input the data and in the data step:
1) make sure that Date of Birth variable is recorded as a SAS date;
2) use SAS arrays and looping to create a SAS date variable for each of the three blood samples and to address the missing data in accordance to the decisions of the investigators. Hint: use a single array and do loop to recode the missing values for day and month, separately, and an array/do loop for creating the SAS date variable;
3) use a SAS function to create a variable for the highest, i.e., maximum, blood lead value for each child;
4) use SAS arrays and looping to identify the date on which this largest value was obtained and create a new variable for the date of the largest blood lead value;
5) determine the age of the child in years when the largest blood lead value was obtained (rounded to two decimal places);
6) create a new variable based on the age of the child in years when the largest lead value was obtained (call it, “agecat”) that takes on three levels: for children less than 4 years old, agecat should equal 1; for children at least 4 years old, but less than 8, agecat should equal 2; and for children at least 8 years of age, agecat should be 3.;
7) print out the variables for the date of birth, date of the largest lead level, age at blood sample for the largest blood lead level, agecat, sex, and the largest blood lead level (Only print out these requested variables). All dates should be formatted to use the mmddyy10. format on the output.
The code I used in response to this was:
libname HW3 'C:\Users\johns\Desktop\SAS';
filename HW3new 'C:\Users\johns\Desktop\SAS\lead_sum2018.txt';
data one;
infile HW3new;
informat dob mmddyy8.;
input #1 id dob dbs1 mbs1
#2 dbs2 mbs2
#3 dbs3 mbs3
#4 bls1 bls2 bls3 sex;
array dbs{3} dbs1 dbs2 dbs3;
array mbs{3} mbs1 mbs2 mbs3;
do i=1 to 3;
if dbs{i}=-9 then dbs{i}=15;
end;
do i=4 to 6;
if mbs{i}=-9 then mbs{i}=6;
end;
array date{3} mdy1 mdy2 mdy3;
do i=1 to 3;
date{i}=mdy(mbs{i}, dbs{i}, 1990);
end;
maxbls=max(of bls1-bls3);
array bls{3} bls1 bls2 bls3;
array maxdte{3} maxdte1 maxdte2 maxdte3;
do i=1 to i=3;
if bls{i}=maxbls then maxdte=i;
end;
agemax=maxdte-dob;
ageest=round(agemax/365.25,2);
if agemax=. then agecat=.;
else if agemax < 4 then agecat=1;
else if 4 <= agemax < 8 then agecat=2;
else if agemax ge 8 then agecat=3;
run;
I received this error:
22 maxbls=max(of bls1-bls3);
23 array bls{3} bls1 bls2 bls3;
24 array maxdte{3} maxdte1 maxdte2 maxdte3;
25 do i=1 to i=3;
26 if bls{i}=maxbls then maxdte=i;
ERROR: Illegal reference to the array maxdte.
27 end;
Does anyone have any tip is regards to this issue? What did I do wrong? Was I supposed to create an additional array for the date of when the maximum blood lead sample value was collected? Thanks!
**I'm stuck on #4 of Part A, but I included the other parts for context. Thanks!
**Edits: I included the data that I had to read into SAS and the file name of the file it came from
Just from looking at the code immediately prior to the error, you have a problem on this line:
26 if bls{i}=maxbls then maxdte=i;
You are getting the error because you are attempting to assign a value to the array maxdte. Arrays cannot be assigned values like that (unless you are using the deprecated do over syntax...) Instead, choose an element of the array and assign the value to the element. E.g. you could do:
26 if bls{i}=maxbls then maxdte{1}=i;
Or instead of a literal 1, you could use a variable containing the relevant array index.
You are not properly handling ID field from lines #2-4
input #1 id dob dbs1 mbs1
#2 dbs2 mbs2
#3 dbs3 mbs3
#4 bls1 bls2 bls3 sex;
For example you need to skip field 1 on line 2-3 or read the ids into array perhaps to check they are all the same.
input #1 id dob dbs1 mbs1
#2 id2 dbs2 mbs2
#3 id3 dbs3 mbs3
#4 id4 bls1 bls2 bls3 sex;
This example show how to check that you have 4 lines with the same ID and if you do read the rest of the variables or execute LOSTCARD. ID 3 has a missing record;
353 data ex;
354 infile cards n=4 stopover;
355 input #1 id #2 id2 #3 id3 #4 id4 #;
356 if id eq id2 eq id3 eq id4
357 then input #1 id dob:mmddyy. dbs1 mbs1
358 #2 id2 dbs2 mbs2
359 #3 id3 dbs3 mbs3
360 #4 id4 bls1 bls2 bls3 sex :$1.;
361 else lostcard;
362 format dob mmddyy.;
363 cards;
NOTE: LOST CARD.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
372 3 01/03/80 11 7
373 3 27 2
374 3 3.24 3.4 3.83 M
375 4 08/01/80 5 12
NOTE: LOST CARD.
376 4 28 -9
NOTE: LOST CARD.
377 4 3 4
NOTE: The data set WORK.EX has 3 observations and 15 variables.
data ex;
infile cards n=4 stopover;
input #1 id #2 id2 #3 id3 #4 id4 #;
if id eq id2 eq id3 eq id4
then input #1 id dob:mmddyy. dbs1 mbs1
#2 id2 dbs2 mbs2
#3 id3 dbs3 mbs3
#4 id4 bls1 bls2 bls3 sex :$1.;
else lostcard;
format dob mmddyy.;
cards;
1 04/30/78 6 10
1 -9 7
1 14 1
1 1.62 1.35 1.47 F
2 05/19/79 27 11
2 20 -9
2 5 6
2 1.71 1.31 1.76 F
3 01/03/80 11 7
3 27 2
3 3.24 3.4 3.83 M
4 08/01/80 5 12
4 28 -9
4 3 4
4 3.1 3.69 3.27 M
;;;;
run;
proc print;
run;

Stat2Data package doesn't allow me to use the objects in it

Stat2Data package contains a lot of exemplary datasets. I get no errors when installing it or using the library function to call it. However, it doesn't allow me to work with the objects.
Anyone familiar with this package and know what I can do about it? Here's the code that I used:
install.packages("Stat2Data")
library(Stat2Data)
# Attempt 1
MedGPA_ds <- ggplot(MedGPA, aes(x = GPA, y = Acceptance))
# Attempt 2
MedGPA_ds <- ggplot(Stat2Data::MedGPA, aes(x = GPA, y = Acceptance))
You have missed just one step, the use of the data() function to call the specific dataset (MedGPA) contained within the Stat2Data package.
Try the following:
library(Stat2Data)
data(MedGPA)
head(MedGPA)
Accept Acceptance Sex BCPM GPA VR PS WS BS MCAT Apps
1 D 0 F 3.59 3.62 11 9 9 9 38 5
2 A 1 M 3.75 3.84 12 13 8 12 45 3
3 A 1 F 3.24 3.23 9 10 5 9 33 19
4 A 1 F 3.74 3.69 12 11 7 10 40 5
5 A 1 F 3.53 3.38 9 11 4 11 35 11
6 A 1 M 3.59 3.72 10 9 7 10 36 5
Happy coding!

Data Structure for Sequence of Event Analysis in R

The code below creates a sample dataframe to illustrate my problem. I have a time stamped list of events.
set.seed(100)
mydf<-data.frame(time=(1:1000),event = sample(1:10,10000,replace=TRUE))
mydf
time event
1 6
2 5
3 7
4 8
5 4
6 2
7 10
8 9
9 4
10 6
11 4
12 3
13 8
14 3
15 9
16 1
17 7
18 3
19 8
20 10
I am trying to create a new variable that lists the previous events in a specified window. say the window is size 10. I would like to create the dataframe below. My ultimate goal is to prepare my data for sequence of events analysis.
time event eventList
1 6 NA
2 5 NA
3 7 NA
4 8 NA
5 4 NA
6 2 NA
7 10 NA
8 9 NA
9 4 NA
10 6 NA
11 4 {6,5,7,8,4,2,10,9,4,6}
12 3 {5,7,8,4,2,10,9,4,6,4}
13 8 {7,8,4,2,10,9,4,6,4,3}
14 3 {8,4,2,10,9,4,6,4,3,8}
15 9 {4,2,10,9,4,6,4,3,8,3}
16 1 {2,10,9,4,6,4,3,8,3,9}
17 7 {10,9,4,6,4,3,8,3,9,1}
18 3 {9,4,6,4,3,8,3,9,1,7}
19 8 {4,6,4,3,8,3,9,1,7,8}
20 10 {6,4,3,8,3,9,1,7,8,10}
The last three rows do not match , could you please check your expected output
mydf=read.table(text="
time event
1 6
2 5
3 7
4 8
5 4
6 2
7 10
8 9
9 4
10 6
11 4
12 3
13 8
14 3
15 9
16 1
17 7
18 3
19 8
20 10",header=TRUE,stringsAsFactors=FALSE)
windowSize = 10
mydf$eventList = do.call(rbind,lapply(mydf$time,function(x) {
ifelse(x<windowSize,NA,paste0("{", paste0(mydf[ tail(1:x,windowSize) ,"event"],collapse=",") , "}"))
}))
mydf
# time event eventList
#1 1 6 <NA>
#2 2 5 <NA>
#3 3 7 <NA>
#4 4 8 <NA>
#5 5 4 <NA>
#6 6 2 <NA>
#7 7 10 <NA>
#8 8 9 <NA>
#9 9 4 <NA>
#10 10 6 {6,5,7,8,4,2,10,9,4,6}
#11 11 4 {5,7,8,4,2,10,9,4,6,4}
#12 12 3 {7,8,4,2,10,9,4,6,4,3}
#13 13 8 {8,4,2,10,9,4,6,4,3,8}
#14 14 3 {4,2,10,9,4,6,4,3,8,3}
#15 15 9 {2,10,9,4,6,4,3,8,3,9}
#16 16 1 {10,9,4,6,4,3,8,3,9,1}
#17 17 7 {9,4,6,4,3,8,3,9,1,7}
#18 18 3 {4,6,4,3,8,3,9,1,7,3}
#19 19 8 {6,4,3,8,3,9,1,7,3,8}
#20 20 10 {4,3,8,3,9,1,7,3,8,10}
I am assuming someone will come up with a more R way of going this, reducing your runtime. Meanwhile you can try this:
for (i in 1:nrow(mydf)){
if(i<=w){
mydf$eventList[i] = NA
}
else {
mydf$eventList[i] = list(mydf$event[c((i-w):i)])
}
}

reading and printing a .csv file like a 2D matrix with both integer and float values in c

Reading a file in c with .csv as extension. The file consisting of both integer and float type data values. Is there any way to read the csv file. Any help is appreciated.
The data is as follows:
Application_No. Actual_Effort (in PM) No of Processes No of Tasks No of partnerLinks Task Variables Element Variables Event Variables Script Developer's Skills Developer's Confidence TPSS TS TCC
1 918.28 1 3 5 33 7 2 3 3.5 1 8 135 143
2 8891.513 3 9 3 100 15 6 12 3 1 36 1197 1233
3 22479.261 5 15 23 125 25 10 20 3 1 190 2700 2890
4 2961.131 2 4 9 70 13 4 17 2 0 72 416 488
5 19650.198 7 14 19 130 28 12 5 2.5 0 231 2450 2681
6 377.75 1 2 4 22 8 2 2 3 1 6 68 74
7 2671.93 1 5 12 55 12 6 4 2 0 17 385 402
8 966.15 3 3 6 31 8 5 7 2.5 0 27 153 180
9 3765.81 2 6 17 73 14 2 3 3.5 1 46 552 590
10 7467.11 4 8 21 87 19 13 1 2 0 116 960 1076

Arduino EEPROM seems flaky, should I write twice?

I am used to programming PC's and smartphones using high level languages, microcontrollers are a new territory for me. Are they somehow different, more untrustworthy, requiring different techniques? Here is bit of code to write and read to EEPROM running on a Arduino Mega: (there is an Ethernet Shield attached, not used here)
#include <EEPROM.h>
int addr = 0;
int val;
byte value;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val = 9;
EEPROM.write(addr, val);
delay(500);
addr = addr + 1;
if (addr == 20) addr = 0;
value = EEPROM.read(addr);
Serial.print(addr);
Serial.print("\t");
Serial.print(value);
Serial.println();
}
Heres what comes out:
1 91
2 91
3 9
4 9
5 9
6 9
7 9
8 9
9 9
10 9
11 9
12 202
13 202
14 202
15 202
16 202
17 202
18 202
19 202
0 9
1 89
2 91
3 9
4 9
5 9
6 9
7 9
8 9
9 9
10 9
11 9
12 9
13 9
14 9
15 9
16 9
.....
In general address 1 and 2 are always flaky and it takes two writes to change memory locations above ~10.
I can switch out another board and still get similar oddities.
How can I adapt my programming to this seemingly flaky performance?
Simply enough, your code is wrong.
Logically step through it. You are writing to an EEPROM at address addr. You then wait 500ms, increment addr, and then read from the new addr. The addr you read from is therefore not the addr you write to.

Resources