[Solved] How do I r...
 
Notifications
Clear all

[Solved] How do I reset a USB device using a script?

0 Posts
1 Users
0 Likes
6 Views
0
Topic starter
RoboJ1M Asks: How do I reset a USB device using a script?
I have a USB GSM modem that does not always work property (Huawei E367u-2) Sometimes it gets reset (USB device disconnect/reconnect in logs) and when it comes back up, it has different ttyUSB numbers. Sometimes on boot, usb_modeswitch seems to just not get fired. The computer is a Raspberry Pi running Raspbian.

I have a simple solution to this: every minute cron runs the following script (pseudo-code):

Code:
If WVDIAL is not running:
    Run WVDIAL

I want to change the script to be this:

Code:
If /dev/ttyUSB0 is not present:
    If DevicePresent(12d1:1446):
        ResetDevice(12d1:1446)
    ElseIf DevicePresent(12d1:1506)
        ResetUSB(12d1:1506)
If WVDIAL is not running:
    Run WVDIAL

Obviously this is pseudo-code, but I have the following lines that I need to string together but I can't figure out how:

This loads wvdial if it is not running:

Code:
#! /bin/sh 
# /etc/init.d/wvdial

### BEGIN INIT INFO
# Provides:          TheInternet
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting GPRS Internet"
    # run application you want to start
    /sbin/start-stop-daemon --start --background --quiet --exec /usr/bin/wvdial internet
    ;;
  stop)
    echo "Stopping GPRS Internet"
    # kill application you want to stop
    /sbin/start-stop-daemon --stop --exec /usr/bin/wvdial 
    ;;
  *)
    echo "Usage: /etc/init.d/noip {start|stop}"
    exit 1
    ;;
esac

exit 0

This lets me find the /sys path to a certain device:

Code:
for X in /sys/bus/usb/devices/*; do
    echo "$X"
    cat "$X/idVendor" 2>/dev/null
    cat "$X/idProduct" 2>/dev/null
    echo
done

And this resets a USB device if you know the correct /sys path:

Code:
echo 0 > /sys/bus/usb/devices/1-1.2.1.1/authorized
echo 1 > /sys/bus/usb/devices/1-1.2.1.1/authorized

So, I need to string together those last 2 sections and a test to /dev/ttyUSB0 into a section that goes under the "If you want a command to always run, put it here" comment.

  • How can I do that?
  • Is there a better way to do this?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

Unreplied Posts

[Solved] MySQL query posts by Tag and Category?

GenesisBits Asks: MySQL query posts by Tag and Category?
I’m building a custom API for my site that will query WordPress posts. My current query is as follows:

Code:
SELECT p.ID, p.post_title, p.post_author, p.post_date, p.post_excerpt
FROM wph3_posts p
INNER JOIN wph3_term_relationships t ON p.ID = t.object_id
INNER JOIN wph3_term_taxonomy tx ON t.term_taxonomy_id = tx.term_taxonomy_id
INNER JOIN wph3_terms tt ON tx.term_id = tt.term_id
WHERE p.post_status = "publish"
AND 1=1 
AND (tt.slug LIKE 'dragon' AND tx.taxonomy = 'post_tag') 
AND (tt.slug LIKE 'decks' AND tx.taxonomy = 'category') 
ORDER BY p.post_date DESC LIMIT 20 OFFSET 0

I’m struggling to search by both tag and category simultaneously

Code:
AND (tt.slug LIKE 'dragon' AND tx.taxonomy = 'post_tag') 
AND (tt.slug LIKE 'decks' AND tx.taxonomy = 'category')

If I exclude either one of those lines, it will search by either the tag or the category. I can’t seem to get them working together.

Any help would be appreciated!

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.
 
 
 

[Solved] Shift in raster in python 3.6

Anna Riling Asks: Shift in raster in python 3.6
I have a python script for a color anomaly detection study. I am attempting to create two rasters each with three classes: one raster representing a “target” and the other representing “background”, or all pixels except those within the target extent. I have tried using a Con(IsNull()) statement as well as ExtractByMask to create the “donut hole” where the target is in the background raster. These methods work, except that the background raster is shifted a few feet to the northwest. The target raster is in the right spot, however. I have created other rasters in the script prior to this step and all are in the correct location geographically. I set the extent, snapRaster, and cellSize to an original “spectral index” raster. Entire code is below.

Why am I seeing a shift in this one and only raster, and how do I prevent it?


Resulting background raster is created correctly, but shifted to the northwest a few feet

Code:
import arcpy
from arcpy import env
from arcpy.sa import *
import numpy as np
from arcpy import os

# To allow overwriting the outputs change the overwrite option to true.
env.overwriteOutput = True

arcpy.CheckOutExtension("spatial")

# define main directory
main_dir = "F:\color_anomaly_workspace\"
env.workspace = main_dir

# read in main ortho dataset
ortho = Raster("F:\color_anomaly_workspace\purple.tif")

# read in our clippers
# clipper = "D:\Google Drive\School\Color Anomaly Detection\GIS\Backgrounds\color_anomaly\color_anomaly.gdb\ortho_clip4"
bg_clipper = "D:\Google Drive\School\Color Anomaly Detection\GIS\Backgrounds\color_anomaly\color_anomaly.gdb\background_clip"
targets = "D:\Google Drive\School\Color Anomaly Detection\GIS\Backgrounds\color_anomaly\color_anomaly.gdb\target_footprint"

# clip the mosaic to the clipper extent
ortho_clip = arcpy.Clip_management(ortho, "241896.71980000008 4137828.0887 241956.74800000008 4137967.415", "purple_clip.tif")

# create indices
basename = arcpy.Describe(ortho_clip).catalogPath
b1 = Raster(basename + "\Band_1")
b2 = Raster(basename + "\Band_2")
b3 = Raster(basename + "\Band_3")

r = Float(b1)
r.save("index_r")
print("writing index_r")

g = Float(b2)
g.save("index_g")
print("writing index_g")

# create CSV
with open("F:\color_anomaly_workspace\results_purple.csv", "w") as csv:
    csv.write("index,sd,plus_minus,tp,fn,bg_anomaly,bg_not_anomalyn")
    print("wrote csv")

# add indices to a list and then begin loop
index_list = [r, g]
print("begin loop")

for index in index_list:
    # calculate focal mean of spectral index
    index_focal = FocalStatistics(index, NbrRectangle(600, 600, "CELL"), "MEAN")
    basename = arcpy.Describe(index).basename
    index_focal.save(basename + "_focal")

    # perform image difference
    diff = index_focal - index
    diff.save(basename + "_diff")

    # get mean and SD
    mean = float(arcpy.GetRasterProperties_management(diff, "MEAN").getOutput(0))
    sd = float(arcpy.GetRasterProperties_management(diff, "STD").getOutput(0))
    min1 = float(arcpy.GetRasterProperties_management(diff, "MINIMUM").getOutput(0))
    max1 = float(arcpy.GetRasterProperties_management(diff, "MAXIMUM").getOutput(0))

    # begin reclassification loop
    multipliers = np.arange(0.50, 1.1, 0.5)
    for multiplier in multipliers:
        high_threshold = mean + multiplier * sd
        low_threshold = mean - multiplier * sd

        # set extent
        arcpy.env.extent = "MAXOF"
        arcpy.env.snapRaster = index
        arcpy.env.cellSize = index

        # reclassify raster
        rc = [[min1, low_threshold, 1],
              [low_threshold, high_threshold, 2],
              [high_threshold, max1, 3]]

        diff_rc = Reclassify(diff, "Value", RemapRange(rc))
        diff_rc.save(basename + "_diff_rc.tif")

        # select out just purple target polygons
        targets_purple = arcpy.Select_analysis(targets, "target_purple", "color = 'purple'")
        arcpy.AddField_management(targets_purple, "raster_id", "SHORT")
        arcpy.CalculateField_management(targets_purple, "raster_id", 1, "PYTHON")
        targets_rast = arcpy.PolygonToRaster_conversion(targets_purple, "raster_id", "targets_purple_rast.tif")

        # clip raster to target extent
        multiplier_name = str(round(int(multiplier * 100),0)).rjust(3,"0")
        diff_rc_target = ExtractByMask(diff_rc, targets_rast)
        diff_rc_target.save(basename + multiplier_name + "_target.tif")

        # convert background clip polygon to raster
        arcpy.AddField_management(bg_clipper, "raster_id", "SHORT")
        arcpy.CalculateField_management(bg_clipper, "raster_id", 1, "PYTHON")
        bg_clipper_rast = arcpy.PolygonToRaster_conversion(bg_clipper, "raster_id", "background_clip_rast.tif")

        # create background raster
        diff_rc_background = ExtractByMask(diff_rc, bg_clipper_rast)
        diff_rc_background.save(basename + multiplier_name + "_background.tif")

        # build attribute table to get cell counts
        arcpy.BuildRasterAttributeTable_management(diff_rc_target)
        arcpy.BuildRasterAttributeTable_management(diff_rc_background)

arcpy.CheckInExtension("spatial")

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] What is the purpose of BAV70 in this schematic?

Singe Asks: What is the purpose of BAV70 in this schematic?
I’ve found this schematic for an Arduino board:


enter image description here

What is the purpose of the two diodes (BAV70) in these two applications?


2021 addendum (RGB)

This is Sparkfun’s Arduino Mini 05 which is based on an ATMega328. Full schematic here.


Mini 05 schematic

(click image to see it full size)

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Building DIY TrackIR, need wiring help

Ferkner Asks: Building DIY TrackIR, need wiring help
I’m attempting to build a homemade head tacking unit for use in computer games using infrared LEDs for my kid. I followed one tutorial where they were wired in parallel. After doing more research, I read posts on here and on Nuts & Volts that wiring LEDs in parallel is not ideal because one or more LEDs will hog the current. This appears to be true because the one LED with the longest distance from the power source always seems dimmer.

I figured out the resistance needed to wire the LEDs in parallel. There are three LEDs with a forward voltage of 1.2V and a continuous forward current of 100mA. They are powered by a 3V source (two AA batteries), requiring a resistance of 6 ohms.

If I wire them in series, the LEDs take more voltage (3.6) than the batteries can supply. I don’t want to move to a bigger battery box as this is head mounted. Can the LEDs still work with a bit less voltage. I did a quick test and they did not seem to light up. Maybe moving to a 9V battery is an option, but those things are far more expensive than AAs :)

If I am stuck with wiring in parallel I read it’s better to put a resistor on each LED diode. How do I calculate the resistor value I on each LED. I know wiring resistors in parallel halves their resistance (thanks Element14!), so if there are three paths, do I need 18 ohm resistors at each LED to get to the 6 overall ohms the circuit needs?

Yes, I am very new to all of this.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] What are the different types of controllers in control system?

ert Asks: What are the different types of controllers in control system?
What are the different types of controllers in control system?

By my study, i am able to understand that there are only two main types:

  1. On-off controller

  2. PID controller

Please guide me,Are there any other types also?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Lightning Web Component Slots in App Builder

Tiaan Swart Asks: Lightning Web Component Slots in App Builder
Need some help, not even sure if this is possible…

In Lightning App Builder, the standard tabs component has “Slots” where tab content can be placed.

My question, is this available for LWC through slots?

I have tried adding <slot><slot> to a component and tried dragging other components into it in the Builder, the UI does not allow this action though.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] How to set my custom view as Default view admin grid Magento 2

kanidhaya Asks: How to set my custom view as Default view admin grid Magento 2
I want to set my custom view as Default view the admin grid section. I tried by saving the view but that is only per user. I want to set it for all the users.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] How do I use API versioning?

Matt Korostoff Asks: How do I use API versioning?
I’m using the Services module to produce a REST API. According to the official documentation, there is a way to version services resources. I believe version here means supplying a single API (e.g. example.com/api) and allowing clients to specify which version they want per resource with headers.

So I think that means that these two requests would return different results, despite living at the same URL:

Version 1.0:

Code:
POST /api/v1/system/set_variable HTTP/1.1
Host: example.com
Accept: application/json
Content-Type: application/json

Version 1.2:

Code:
POST /api/v1/system/set_variable HTTP/1.1
Host: example.com
Accept: application/json
Content-Type: application/json
services_system_set_variable_version: 1.2

I cannot make this work for the life of me. Here are the steps I took:

  1. Enabled the system/set_variable service

    {
    “lightbox_close”: “Close”,
    “lightbox_next”: “Next”,
    “lightbox_previous”: “Previous”,
    “lightbox_error”: “The requested content cannot be loaded. Please try again later.”,
    “lightbox_start_slideshow”: “Start slideshow”,
    “lightbox_stop_slideshow”: “Stop slideshow”,
    “lightbox_full_screen”: “Full screen”,
    “lightbox_thumbnails”: “Thumbnails”,
    “lightbox_download”: “Download”,
    “lightbox_share”: “Share”,
    “lightbox_zoom”: “Zoom”,
    “lightbox_new_window”: “New window”,
    “lightbox_toggle_sidebar”: “Toggle sidebar”
    }

    system
  2. Added the following code to mymodule.module (cribbed directly from services.versions.api.php)

.

Code:
function _system_resource_set_variable_update_1_1() {
  $new_set = array(
    'help' => 'Create a node with an nid test',
  );
  return $new_set;
}

function _system_resource_set_variable_update_1_2() {
  $new_set = array(
    'help' => 'Create a node with an nid optional prams.',
    'args' => array(
      array(
        'name' => 'name',
        'optional' => TRUE,
        'source' => array('data' => 'name'),
        'description' => t('The name of the variable to set.'),
        'type' => 'string',
      ),
      array(
        'name' => 'value',
        'optional' => TRUE,
        'source' => array('data' => 'value'),
        'description' => t('The value to set.'),
        'type' => 'string',
      ),
    ),
  );
  return $new_set;
}

  1. Cleared cache
  2. Attempted to use the system/set_variable service with postman.
  3. Saw that the system/set_variable service was working

    postman
  4. Attempted to use the system/set_variable service without arguments, per _system_resource_set_variable_update_1_2

  5. Saw that arguments were still required
    postman1

So what am I doing wrong here? I’m pretty sure I followed all the instructions.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] ssis control flow loop

gdw Asks: ssis control flow loop

enter image description here

I need an SSIS package that loops back to the initial execute task after the wait for delay block is executed. here is the logic for the below package: execute SQL task executes a set of commands and after that if a condition is met, the second process(preparation sql task 1 and so on) will be executed. if the condition is not met, it will wait for some time and re-run the first task(execute sql task). I am stuck here and cannot go any further. please help

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Recalculate and replace large table without interrupting table reads

Denziloe Asks: Recalculate and replace large table without interrupting table reads
There’s a large table in the database containing statistical information. This table must be read frequently (by lookups which return a single row).

This table must be completely recalculated every so often. There’s a procedure which does the calculation. Currently it does this into a temporary table, and then when it’s done it truncates the real table and inserts the data from the temporary table into it.

The problem is that this truncation and insertion takes a while and interrupts lookups during that time. The question is how to do it without interrupting lookups, or only interrupting lookups very briefly.

I’d be happy to hear all options which achieve the desired behaviour; the solution doesn’t necessarily have to involve a temporary table. Sorry if this is an established common problem — I wasn’t sure which terms to search.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

Share: