Trying to do some Swift stuff. Converting some USB device detection code from Objective-C to Swift. Having a problem with getting the Notification port. IONotificationPortCreate returns a Unmanaged<'IONotificationPort'>! and when the program runs it hangs on line 2 below and I then printed out the description of notify and notifyPort below. I don't know if it's not getting the port or if I'm not getting it out of that Unmanaged <'IONotificationPort'>! correctly or something else is wrong
var notify = IONotificationPortCreate(kIOMasterPortDefault)
var notifyPort = notify.takeRetainedValue() as IONotificationPortRef
Printing description of notify: (Unmanaged<'IONotificationPort'>!) notify = (_value = <no summary available>)
Printing description of notifyPort: (IONotificationPortRef) notifyPort = 0x000000010050e620 {}
Thanks for any help,
Chris
Related
I am trying to copy a tutorial for a Wordle solving bot but its just not going well. whenever I try to run a test on the code it doesn't work at certain points, I'll either get 'Uncaught SyntaxError: Unexpected identifier'. I'm doing this on UIlicious.
Here's what I've got so far:
I.goTo("https://www.powerlanguage.co.uk/wordle/")
I.click("reject")
I.see("Guess the Wordle")
I.click('/html/body', 40, 80)
let guessWord = null
for(Let r=0 ; r<6 ; ++r) {
guessWord = solver.suggestWord(gameState)
I.type(guessWord);
I.pressEnter()
I.wait(2)
}
let rowList = document.querySelector("game-app").shadowRoot. //
querySelector("game-theme-manager"). //
querySelector("#board").querySelectorAll("game-row");
you are probably referring to the article I wrote here : https://uilicious.com/blog/automate-wordle-via-uilicious/
This test script, is designed specifically to use uilicious.com, so you will need to edit and run it through the platform.
You can do so via the snippet here : https://snippet.uilicious.com/test/public/N5qZKraAaBsAgFuSN8wxCL
If you have syntax error there, do let me know with a snippet link - and I will try to help you respectively.
Also the snippet you provided so far, excludes the "solver" class which was initialised much further down.
I am working with a project where I don't get it the value of
awsiotdatamanager is static string or it generated from AWS. I found it like this in sample code Also I read code this and this but I am getting more and more confused.
let AWSIoTDataManager = "MyIotDataManager"
let iotDataManager = AWSIoTDataManager(forKey: AWSIoTDataManager)
Thanks in advance :)
I have this stack trace in Crashlytics:
The source code are running is below:
#objc private func playerTimerTick() {
mediaDurationInSeconds = Int32(mediaDuration)
mediaCurrentPositionInSeconds = Int32(currentTimeInSeconds)
if elapsedTimeNeedStoreStartPosition {
elapsedTimeNeedStoreStartPosition = false
elapsedTimeStartPosition = mediaCurrentPositionInSeconds
}
}
The line 1092 is mediaDurationInSeconds = Int32(mediaDuration).
The mediaDuration variable is a Double type and receive a duration in seconds from a AVURLAsset.
This method (playerTimerTick) is running by a Timer.scheduledTimer every 1 second. I have already performed several debugs of this source code and this function and there is no crash. But in the release version is occurring with multiple users and without any explanation.
Has anyone ever had anything like this or do you have any idea what might be causing this crash?
im new in ionic, right now i'm trying to send a "code" in string.
which the string consist of a few packets data in HEX.
eg. V1-FC03-2ED1-FE01
V1 is the sequence, then after the first - is the first packet "FC03"
the code successfully send to my arduino using serial monitor on pc.
arduino serial monitor
now i want to send it trough BLE using ionic.
i follow the example on github on doing the BLE.
it works if send 1 or 0.
here is the function in ionic codes that going to send to arduino after button pressed
onPowerSwitchChange(event) {
console.log('onPowerSwitchChange');
let value = this.power ? 1 : 0;
let buffer = new Uint8Array([value]).buffer;
console.log('Power Switch Property ' + this.power);
this.ble.write(this.peripheral.id, LIGHTBULB_SERVICE, SWITCH_CHARACTERISTIC, buffer).then(
() => this.setStatus('Light is ' + (this.power ? 'on' : 'off')),
e => this.showAlert('Unexpected Error', 'Error updating power switch')
);
}
here i tried to change
let value = this.power ? 1 : 0;
to
let value = "V1-FC03-2ED1-FE01";
but when compile, got error
Argument of type 'string[]' is not assignable to parameter of type 'ArrayBuffer'. Property 'byteLength' is
missing in type 'string[]'.
L68: let value = "V1-FC03-2ED1-FE01";
L69: let buffer = new Uint8Array([value]).buffer;
L70: console.log('Power Switch Property ' + this.power);
hopefully someone can help me on this problem
Not sure if this will help you as I'm not a programmer by trade... but I wanted to send a "2" as string and it turned out that I had to do it like this:
var data = new Uint8Array(1);
data[0] = 50;
With 50 being the Uint8Array equivalent of 2
Currently I'm trying to read from the BLE in the opposite direction to no effect so please keep us posted as to your progress.
When I use MongoEngine to add an embedded doc to a doc, it works the first time when the list is empty but fails with subsequent tries saying: mongoengine.errors.OperationError: Could not save document (Cannot update 'sensorlist.1.alert_list.0._cls' and 'sensorlist.1.alert_list' at the same time)
The following test code demonstrates the issue: If you run it once you will see a new collection/document in foo that has an S2 embedded Sensor with qty 2 embedded Alerts. If you run it again it blows up - Any ideas?
Thx Bill
import mongoengine as ME
ME.connect('foo')
class Sensor(ME.EmbeddedDocument):
name = ME.StringField()
alert_list = ME.ListField()
class Alert(ME.EmbeddedDocument):
name = ME.StringField(default = 'new alert')
class SiteConfig(ME.Document):
siteid = ME.StringField()
sensorlist = ME.ListField(ME.EmbeddedDocumentField(Sensor))
if not SiteConfig.objects(siteid = '123456'):
newsite = SiteConfig(siteid = '123456')
newsite.save()
print("saved new site")
site = SiteConfig.objects(siteid = '123456').first()
newsensor = Sensor(name='S1')
site.sensorlist.append(newsensor)
site.save()
print("added sensor S1")
newsensor = Sensor(name='S2')
site.sensorlist.append(newsensor)
site.save()
print("added sensor S2")
for sensor in site.sensorlist:
if sensor.name =='S2':
alert = Alert()
sensor.alert_list.append(alert)
site.save()
print('added first alert to S2')
for sensor in site.sensorlist:
if sensor.name =='S2':
alert = Alert()
sensor.alert_list.append(alert)
site.save()
print('added second alert to S1')
I solved this by reproducing the code in MongoAlchemy which is very similar. That also failed but actually gave me useful exception info that pointed me to the problem which was that my Sensor class Alert_list definition needed to specify the class it contains.
So the fix is to define Sensor like this:
class Sensor(ME.DynamicEmbeddedDocument):
name = ME.StringField()
alert_list = ME.ListField(ME.EmbeddedDocumentField(Alert))
After all that pain over such a small issue I will probably stick with MongoAlchemy!